Skip to content

Commit 7a73900

Browse files
committed
MAGE-1134: re-add synonyms deduplication logic from previous PRs in AlgoliaConnector
1 parent 386a1cd commit 7a73900

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

Service/AlgoliaConnector.php

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

352-
$removes = ['slaves', 'replicas', 'decompoundedAttributes'];
353-
354-
if (isset($onlineSettings['mode']) && $onlineSettings['mode'] == 'neuralSearch') {
355-
$removes[] = 'mode';
356-
}
357-
358352
if (isset($settings['attributesToIndex'])) {
359353
$settings['searchableAttributes'] = $settings['attributesToIndex'];
360354
unset($settings['attributesToIndex']);
@@ -365,7 +359,7 @@ public function mergeSettings($indexName, $settings, string $mergeSettingsFrom =
365359
unset($onlineSettings['attributesToIndex']);
366360
}
367361

368-
foreach ($removes as $remove) {
362+
foreach ($this->getSettingsToRemove($onlineSettings) as $remove) {
369363
if (isset($onlineSettings[$remove])) {
370364
unset($onlineSettings[$remove]);
371365
}
@@ -378,6 +372,34 @@ public function mergeSettings($indexName, $settings, string $mergeSettingsFrom =
378372
return $onlineSettings;
379373
}
380374

375+
/**
376+
* These settings are to be managed by other processes
377+
* @param string[] $onlineSettings
378+
* @return string[]
379+
*/
380+
protected function getSettingsToRemove(array $onlineSettings): array
381+
{
382+
$removals = ['slaves', 'replicas', 'decompoundedAttributes'];
383+
384+
if (isset($onlineSettings['mode']) && $onlineSettings['mode'] == 'neuralSearch') {
385+
$removals[] = 'mode';
386+
}
387+
388+
return array_merge($removals, $this->getSynonymSettingNames());
389+
}
390+
391+
/**
392+
* @return string[]
393+
*/
394+
protected function getSynonymSettingNames(): array
395+
{
396+
return [
397+
'synonyms',
398+
'altCorrections',
399+
'placeholders'
400+
];
401+
}
402+
381403
/**
382404
* Legacy function signature to add objects to Algolia
383405
* @param array $objects

0 commit comments

Comments
 (0)