Skip to content

Commit

Permalink
Add creators field while indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Richter committed Jan 6, 2025
1 parent 34bdebe commit 2d07dc4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
13 changes: 6 additions & 7 deletions Classes/Processing/BibElasticMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,17 @@ public static function getMappingParams(string $index): array
]
],
'fulltext' => [ 'type' => 'text' ],
'tx_lisztcommon_header' => [ 'type' => 'text' ],
'tx_lisztcommon_body' => [ 'type' => 'text' ],
'tx_lisztcommon_footer' => [ 'type' => 'text' ],
'tx_lisztcommon_searchable' => ['type' => 'text', 'copy_to' => 'fulltext'],
'tx_lisztcommon_boosted' => ['type' => 'text'],
'tx_lisztcommon_creators' => [
BibEntryProcessor::HEADER_FIELD => [ 'type' => 'text' ],
BibEntryProcessor::BODY_FIELD => [ 'type' => 'text' ],
BibEntryProcessor::FOOTER_FIELD => [ 'type' => 'text' ],
BibEntryProcessor::SEARCHABLE_FIELD => ['type' => 'text', 'copy_to' => 'fulltext'],
BibEntryProcessor::BOOSTED_FIELD => ['type' => 'text'],
BibEntryProcessor::CREATORS_FIELD => [
'type' => 'nested',
'properties' => [
'fullName' => ['type' => 'text'],
]
],

]
]
]
Expand Down
23 changes: 23 additions & 0 deletions Classes/Processing/BibEntryConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,29 @@ class BibEntryConfig
[ 'field' => 'date' ]
];

const CREATORS_FIELD = [
[
'compoundArray' => [
'fields' => [
[
'field' => 'firstName',
'conditionField' => 'creatorType',
'conditionValue' => 'translator',
'conditionRelation' => 'neq'
],
[
'field' => 'lastName',
'conditionField' => 'creatorType',
'conditionValue' => 'translator',
'conditionRelation' => 'neq'
]
],
'field' => 'creators',
'separator' => ' '
]
]
];

public static function getAuthorHeader(): array
{
return [ self::AUTHOR ];
Expand Down
30 changes: 26 additions & 4 deletions Classes/Processing/BibEntryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

class BibEntryProcessor extends IndexProcessor
{
const CREATORS_FIELD = 'tx_lisztbibliography_creators';

public static function process(
array $bibliographyItem,
Expand Down Expand Up @@ -56,21 +57,27 @@ public static function process(
$bibliographyItem[self::SEARCHABLE_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::SEARCHABLE_FIELDS);
$bibliographyItem[self::BOOSTED_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::BOOSTED_FIELDS);

$bibliographyItem[self::CREATORS_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::CREATORS_FIELD);

return $bibliographyItem;
}

public static function buildListingField(
array $bibliographyItem,
array $fieldConfig
): Stringable
): Stringable|array
{
return Collection::wrap($fieldConfig)->
map( function($field) use ($bibliographyItem) { return self::buildListingEntry($field, $bibliographyItem); })->
$collectedFields = Collection::wrap($fieldConfig)->
map( function($field) use ($bibliographyItem) { return self::buildListingEntry($field, $bibliographyItem); });
if (is_array($collectedFields->get(0))) {
return $collectedFields->get(0);
}
return $collectedFields->
join('')->
trim();
}

private static function buildListingEntry(array $field, array $bibliographyItem): ?Stringable
private static function buildListingEntry(array $field, array $bibliographyItem): Stringable|array|null
{
// return empty string if field does not exist
if (
Expand All @@ -81,6 +88,21 @@ private static function buildListingEntry(array $field, array $bibliographyItem)
) {
return null;
}

// return an array when compoundArray option is set
if (isset($field['compoundArray'])) {
// build compound fields
return Collection::wrap($bibliographyItem[$field['compoundArray']['field']])->
// get selected strings
map(function ($bibliographyCell) use ($field) {
return self::processCompound($field['compoundArray'], $bibliographyCell);
})->
// filter out non fitting fields
filter()->
toArray();
$bodyString = Str::of($compoundString);
}

// return empty string if conditions are not met
if (
isset($field['conditionField']) &&
Expand Down

0 comments on commit 2d07dc4

Please sign in to comment.