Skip to content

Commit

Permalink
outsource mapping config in separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-sc committed Nov 27, 2024
1 parent 73c2f6b commit 28ce97e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 58 deletions.
60 changes: 2 additions & 58 deletions Classes/Command/IndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Psr\Log\LoggerInterface;
use Slub\LisztCommon\Common\ElasticClientBuilder;
use Slub\LisztBibliography\Processing\BibEntryProcessor;
use Slub\LisztBibliography\Processing\BibElasticMapping;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -143,64 +144,7 @@ protected function fullSync(InputInterface $input): void
$this->bibliographyItems = $collection->pluck('data');
$cursor = 0; // set Cursor to 0, not to bulk size
$index = $this->extConf['elasticIndexName'];

// create a field "fulltext" and copy content of "tx_lisztcommon_searchable" to fulltext
// ToDo: outsorce mapping to BibEntryMapping?
// ToDo: stemming field fulltext german in Fulltext?
$mappingParams = [
'index' => $index,
'body' => [
'mappings' => [
'dynamic' => false,
'properties' => [
'version' => [ 'type' => 'long' ],
'title' => [ 'type' => 'text'],
'university' => [ 'type' => 'text'],
'bookTitle' => [ 'type' => 'text'],
'series' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'publicationTitle' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'place' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'date' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'archiveLocation' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'itemType' => [ 'type' => 'keyword'],
'journalTitle' => [ 'type' => 'keyword'],
'creators' => [
'type' => 'nested',
'properties' => [
'creatorType' => [
'type' => 'keyword'
],
'firstName' => [
'type' => 'text',
'fields' => [
'keyword' => [
'type' => 'keyword', 'ignore_above' => 256
],
],
'copy_to' => 'creators.fullName'
],
'lastName' => [
'type' => 'text',
'fields' => [
'keyword' => [
'type' => 'keyword', 'ignore_above' => 256
]
],
'copy_to' => 'creators.fullName'
],
'fullName' => ['type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword'] ] ],
]
],
'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'],
]
]
]
];
$mappingParams = BibElasticMapping::getMappingParams($index);

try {
// in older Elasticsearch versions (until 7) exists returns a bool
Expand Down
67 changes: 67 additions & 0 deletions Classes/Processing/BibElasticMapping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);

namespace Slub\LisztBibliography\Processing;

// create a field "fulltext" and copy content of "tx_lisztcommon_searchable" to fulltext

class BibElasticMapping
{
public static function getMappingParams(string $index): array
{
return [
'index' => $index,
'body' => [
'mappings' => [
'dynamic' => false,
'properties' => [
'version' => [ 'type' => 'long' ],
'title' => [ 'type' => 'text'],
'university' => [ 'type' => 'text'],
'bookTitle' => [ 'type' => 'text'],
'series' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'publicationTitle' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'place' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'date' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'archiveLocation' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'itemType' => [ 'type' => 'keyword'],
'journalTitle' => [ 'type' => 'keyword'],
'creators' => [
'type' => 'nested',
'properties' => [
'creatorType' => [
'type' => 'keyword'
],
'firstName' => [
'type' => 'text',
'fields' => [
'keyword' => [
'type' => 'keyword', 'ignore_above' => 256
],
],
'copy_to' => 'creators.fullName'
],
'lastName' => [
'type' => 'text',
'fields' => [
'keyword' => [
'type' => 'keyword', 'ignore_above' => 256
]
],
'copy_to' => 'creators.fullName'
],
'fullName' => ['type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword'] ] ],
]
],
'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'],
]
]
]
];
}
}

0 comments on commit 28ce97e

Please sign in to comment.