diff --git a/Classes/Processing/BibElasticMapping.php b/Classes/Processing/BibElasticMapping.php index faf2605..ea813e2 100644 --- a/Classes/Processing/BibElasticMapping.php +++ b/Classes/Processing/BibElasticMapping.php @@ -49,7 +49,7 @@ public static function getMappingParams(string $index): array ] ], ], - 'fullName' => ['type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword'] ] ], + BibEntryProcessor::FULLNAME_KEY => ['type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword'] ] ], ] ], 'fulltext' => [ 'type' => 'text' ], @@ -61,7 +61,7 @@ public static function getMappingParams(string $index): array BibEntryProcessor::CREATORS_FIELD => [ 'type' => 'nested', 'properties' => [ - 'fullName' => [ + BibEntryProcessor::FULLNAME_KEY => [ 'type' => 'text', 'fields' => [ 'keyword' => [ diff --git a/Classes/Processing/BibEntryProcessor.php b/Classes/Processing/BibEntryProcessor.php index 422a926..0f1c899 100644 --- a/Classes/Processing/BibEntryProcessor.php +++ b/Classes/Processing/BibEntryProcessor.php @@ -21,6 +21,7 @@ class BibEntryProcessor extends IndexProcessor { const CREATORS_FIELD = 'tx_lisztbibliography_creators'; + const FULLNAME_KEY = 'fullName'; public static function process( array $bibliographyItem, @@ -65,7 +66,7 @@ public static function process( public static function buildListingField( array $bibliographyItem, array $fieldConfig - ): Stringable|array + ): Stringable { $collectedFields = Collection::wrap($fieldConfig)-> map( function($field) use ($bibliographyItem) { return self::buildListingEntry($field, $bibliographyItem); }); @@ -86,33 +87,34 @@ public static function buildListingField( public static function buildNestedField( array $bibliographyItem, array $fieldConfig - ): Stringable|array + ): array { - $collectedFields = Collection::wrap($fieldConfig) - ->map(function ($field) use ($bibliographyItem) { + return Collection::wrap($fieldConfig)-> + map(function ($field) use ($bibliographyItem) { return self::buildListingEntry($field, $bibliographyItem); - }); - - $result = $collectedFields->flatMap(function ($item) { - if (is_array($item)) { - return array_map(function ($i) { - // convert stringable to string if needed - if ($i instanceof Illuminate\Support\Stringable) { - $i = (string)$i; - } - return ['fullName' => $i]; - }, $item); - } - - // return fullName keys, ToDo: hardcoded key here - if ($item instanceof Illuminate\Support\Stringable) { - return [['fullName' => (string)$item]]; - } + })-> + flatMap(function (array $item): Collection { + //if (is_array($item)) { -> @Thomas do we need this? + return Collection::wrap($item)->map( function ($i) { + // convert stringable to string if needed -> @Thomas strings are autoconverted for me? + //if ($i instanceof Illuminate\Support\Stringable) { + //$i = (string)$i; + //} + return [self::FULLNAME_KEY => $i]; + }); + //} + + // return fullName keys, ToDo: hardcoded key here -> @Thomas do we need this? Can a stringable be supplied here? + if ($item instanceof Illuminate\Support\Stringable) { + return [[self::FULLNAME_KEY => (string)$item]]; + } + // @Thomas if we don't need the type checks, we can just return [self::FULLNAME_KEY => self::buildListingEntry($field, $bibliographyItem)] in the very first mapping function + // For me, indexing works without those type checks - throw new \UnexpectedValueException('Unexpected type: ' . gettype($item)); - })->toArray(); + throw new \UnexpectedValueException('Unexpected type: ' . gettype($item)); + })->toArray(); - return $result; + //return $result; /*Array returns: (