Skip to content

Commit 271a031

Browse files
committed
MAGE-1153 Handle additional synonym use cases
1 parent e11d039 commit 271a031

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
@@ -359,12 +359,6 @@ public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')
359359
} catch (\Exception $e) {
360360
}
361361

362-
$removes = ['slaves', 'replicas', 'decompoundedAttributes', 'synonyms'];
363-
364-
if (isset($onlineSettings['mode']) && $onlineSettings['mode'] == 'neuralSearch') {
365-
$removes[] = 'mode';
366-
}
367-
368362
if (isset($settings['attributesToIndex'])) {
369363
$settings['searchableAttributes'] = $settings['attributesToIndex'];
370364
unset($settings['attributesToIndex']);
@@ -375,7 +369,7 @@ public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')
375369
unset($onlineSettings['attributesToIndex']);
376370
}
377371

378-
foreach ($removes as $remove) {
372+
foreach ($this->getSettingsToRemove($onlineSettings) as $remove) {
379373
if (isset($onlineSettings[$remove])) {
380374
unset($onlineSettings[$remove]);
381375
}
@@ -388,6 +382,34 @@ public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')
388382
return $onlineSettings;
389383
}
390384

385+
/**
386+
* These settings are to be managed by other processes
387+
* @param string[] $onlineSettings
388+
* @return string[]
389+
*/
390+
protected function getSettingsToRemove(array $onlineSettings): array
391+
{
392+
$removals = ['slaves', 'replicas', 'decompoundedAttributes'];
393+
394+
if (isset($onlineSettings['mode']) && $onlineSettings['mode'] == 'neuralSearch') {
395+
$removals[] = 'mode';
396+
}
397+
398+
return array_merge($removals, $this->getSynonymSettingNames());
399+
}
400+
401+
/**
402+
* @return string[]
403+
*/
404+
protected function getSynonymSettingNames(): array
405+
{
406+
return [
407+
'synonyms',
408+
'altCorrections',
409+
'placeholders'
410+
];
411+
}
412+
391413
/**
392414
* Legacy function signature to add objects to Algolia
393415
* @param array $objects

0 commit comments

Comments
 (0)