Skip to content

Commit

Permalink
Merge pull request #55 from soee/avoidTheSameVersionToBeStoredMultipl…
Browse files Browse the repository at this point in the history
…eTimes

#39 Avoid adding the same snippet version into index multiple times
  • Loading branch information
linawolf authored Feb 15, 2024
2 parents 4dde12e + 1667e95 commit d82444d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Repository/ElasticRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ public function addOrUpdateDocument(array $snippet): void
$urlFragment = str_replace('/', '-', $snippet['manual_title'] . '-' . $snippet['relative_url'] . '-' . $snippet['content_hash']);
$documentId = $urlFragment . '-' . $snippet['fragment'];

$script = new Script('ctx._source.manual_version.add(params.manual_version)');
$scriptCode = <<<EOD
if (!ctx._source.manual_version.contains(params.manual_version)) {
ctx._source.manual_version.add(params.manual_version);
}
EOD;
$script = new Script($scriptCode);
$script->setParam('manual_version', $snippet['manual_version']);
$snippet['manual_version'] = [$snippet['manual_version']];
$script->setUpsert($snippet);
Expand Down

0 comments on commit d82444d

Please sign in to comment.