Skip to content

Commit

Permalink
first test with mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-sc committed Nov 18, 2024
1 parent 1461895 commit 7c5181e
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions Classes/Command/IndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ protected function getRequest(): ServerRequestInterface
return $GLOBALS['TYPO3_REQUEST'];
}


// ddev typo3 liszt-bibliography:index -t 100 // index only 100 docs for testing and dev
protected function configure(): void
{
$this->setDescription('Create elasticsearch index from zotero bibliography')->
Expand Down Expand Up @@ -141,17 +143,33 @@ 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: stemming german in Fulltext?
// ToDo: "mappings": {"dynamic": false, // Prevents automatic mapping of all fields to then make individual fields searchable with "properties": {"first_name": { "type": "text"...
$mappingParams = [
'index' => $index,
'body' => [
'mappings' => [
'properties' => [
'fulltext' => [ 'type' => 'text' ],
'tx_lisztcommon_searchable' => ['type' => 'text', 'copy_to' => 'fulltext'],
]
]
]
];

try {
// in older Elasticsearch versions (until 7) exists returns a bool
if ($this->client->indices()->exists(['index' => $index])) {
$this->client->indices()->delete(['index' => $index]);
$this->client->indices()->create(['index' => $index]);
$this->client->indices()->create($mappingParams);
}
} catch (\Exception $e) {
// other versions return a Message object
if ($e->getCode() === 404) {
$this->io->note("Index: " . $index . " does not exist. Trying to create new index.");
$this->client->indices()->create(['index' => $index]);
$this->client->indices()->create($mappingParams);
} else {
$this->io->error("Exception: " . $e->getMessage());
$this->logger->error('Bibliography sync unsuccessful. Error creating elasticsearch index.');
Expand Down Expand Up @@ -348,6 +366,7 @@ protected function commitBibliography(): void
$index = $this->extConf['elasticIndexName'];

$params = [ 'body' => [] ];

$bulkCount = 0;
foreach ($this->dataSets as $document) {
$params['body'][] = [ 'index' =>
Expand All @@ -366,7 +385,7 @@ protected function commitBibliography(): void
$this->client->bulk($params);
}

protected function commitLocales(): void
/* protected function commitLocales(): void
{
$localeIndex = $this->extConf['elasticLocaleIndexName'];
$this->io->text('Committing the ' . $localeIndex . ' index');
Expand All @@ -390,5 +409,5 @@ protected function commitLocales(): void
$this->client->bulk($params);
$this->io->text('done');
}
}*/
}

0 comments on commit 7c5181e

Please sign in to comment.