Skip to content

Commit

Permalink
Merge pull request #3010 from romainruaud/fix_thesaurus-backport
Browse files Browse the repository at this point in the history
Backport synonym fix from Gally and better check on self-included syn…
  • Loading branch information
romainruaud authored Jul 27, 2023
2 parents 1cf82d9 + 611ffd0 commit 599d230
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/module-elasticsuite-thesaurus/Model/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,13 @@ private function getConfig(ContainerConfigurationInterface $containerConfig)
*/
private function getSynonymRewrites($storeId, $queryText, $type, $maxRewrites)
{
$indexName = $this->getIndexAlias($storeId);
$analyzedQueries = $this->getQueryCombinations($storeId, $queryText);
$synonymByPositions = [];
$synonyms = [];
$indexName = $this->getIndexAlias($storeId);
$analyzedQueries = $this->getQueryCombinations($storeId, $queryText);
$synonyms = [];

foreach ($analyzedQueries as $query) {
$synonymByPositions = [];

try {
$analysis = $this->client->analyze(
['index' => $indexName, 'body' => ['text' => (string) $query, 'analyzer' => $type]]
Expand All @@ -235,9 +236,9 @@ private function getSynonymRewrites($storeId, $queryText, $type, $maxRewrites)
$positionKey = sprintf('%s_%s', $token['start_offset'], $token['end_offset']);
$token['token'] = str_replace('_', ' ', $token['token']);
// Prevent a token already contained in the query to be added.
// Eg : you have a synonyme between "dress" and "red dress".
// Eg : you have a synonym between "dress" and "red dress".
// If someone search for "red dress", you don't want the final query to be "red red dress".
if (stripos($queryText, $token['token']) === false) {
if (array_search($token['token'], str_replace('_', ' ', $analyzedQueries)) === false) {
$synonymByPositions[$positionKey][] = $token;
}
}
Expand Down

0 comments on commit 599d230

Please sign in to comment.