Skip to content

Commit

Permalink
Proposals for streamlining indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Richter committed Jan 9, 2025
1 parent dbd35c6 commit 9c6394b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Classes/Processing/BibElasticMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ],
Expand All @@ -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' => [
Expand Down
50 changes: 26 additions & 24 deletions Classes/Processing/BibEntryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
class BibEntryProcessor extends IndexProcessor
{
const CREATORS_FIELD = 'tx_lisztbibliography_creators';
const FULLNAME_KEY = 'fullName';

public static function process(
array $bibliographyItem,
Expand Down Expand Up @@ -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); });
Expand All @@ -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:
(
Expand Down

0 comments on commit 9c6394b

Please sign in to comment.