From 2d07dc46edbd7f115b13703e5842ae4ec71217ef Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Mon, 6 Jan 2025 14:47:03 +0100 Subject: [PATCH] Add creators field while indexing --- Classes/Processing/BibElasticMapping.php | 13 +++++----- Classes/Processing/BibEntryConfig.php | 23 ++++++++++++++++++ Classes/Processing/BibEntryProcessor.php | 30 ++++++++++++++++++++---- 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/Classes/Processing/BibElasticMapping.php b/Classes/Processing/BibElasticMapping.php index b470f77..99e124c 100644 --- a/Classes/Processing/BibElasticMapping.php +++ b/Classes/Processing/BibElasticMapping.php @@ -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'], ] ], - ] ] ] diff --git a/Classes/Processing/BibEntryConfig.php b/Classes/Processing/BibEntryConfig.php index 108d7f4..1018209 100644 --- a/Classes/Processing/BibEntryConfig.php +++ b/Classes/Processing/BibEntryConfig.php @@ -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 ]; diff --git a/Classes/Processing/BibEntryProcessor.php b/Classes/Processing/BibEntryProcessor.php index 170d862..c11a9ec 100644 --- a/Classes/Processing/BibEntryProcessor.php +++ b/Classes/Processing/BibEntryProcessor.php @@ -20,6 +20,7 @@ class BibEntryProcessor extends IndexProcessor { + const CREATORS_FIELD = 'tx_lisztbibliography_creators'; public static function process( array $bibliographyItem, @@ -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 ( @@ -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']) &&