Skip to content

Commit d4e687a

Browse files
authored
Merge pull request #1658 from algolia/fix/MAGE-1153-duplicate-synonyms
MAGE-1153 additional synonym use cases
2 parents 7d9926e + 2b91e71 commit d4e687a

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

Helper/AlgoliaHelper.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,6 @@ public function mergeSettings($indexName, $settings, string $mergeSettingsFrom =
371371
} catch (Exception $e) {
372372
}
373373

374-
$removes = ['slaves', 'replicas', 'decompoundedAttributes', 'synonyms'];
375-
376-
if (isset($onlineSettings['mode']) && $onlineSettings['mode'] == 'neuralSearch') {
377-
$removes[] = 'mode';
378-
}
379-
380374
if (isset($settings['attributesToIndex'])) {
381375
$settings['searchableAttributes'] = $settings['attributesToIndex'];
382376
unset($settings['attributesToIndex']);
@@ -387,7 +381,7 @@ public function mergeSettings($indexName, $settings, string $mergeSettingsFrom =
387381
unset($onlineSettings['attributesToIndex']);
388382
}
389383

390-
foreach ($removes as $remove) {
384+
foreach ($this->getSettingsToRemove($onlineSettings) as $remove) {
391385
if (isset($onlineSettings[$remove])) {
392386
unset($onlineSettings[$remove]);
393387
}
@@ -400,6 +394,34 @@ public function mergeSettings($indexName, $settings, string $mergeSettingsFrom =
400394
return $onlineSettings;
401395
}
402396

397+
/**
398+
* These settings are to be managed by other processes
399+
* @param string[] $onlineSettings
400+
* @return string[]
401+
*/
402+
protected function getSettingsToRemove(array $onlineSettings): array
403+
{
404+
$removals = ['slaves', 'replicas', 'decompoundedAttributes'];
405+
406+
if (isset($onlineSettings['mode']) && $onlineSettings['mode'] == 'neuralSearch') {
407+
$removals[] = 'mode';
408+
}
409+
410+
return array_merge($removals, $this->getSynonymSettingNames());
411+
}
412+
413+
/**
414+
* @return string[]
415+
*/
416+
protected function getSynonymSettingNames(): array
417+
{
418+
return [
419+
'synonyms',
420+
'altCorrections',
421+
'placeholders'
422+
];
423+
}
424+
403425
/**
404426
* Legacy function signature to add objects to Algolia
405427
* @param array $objects

0 commit comments

Comments
 (0)