From 17acb3cb1e017a48048d8b9c2575d2c84657ee78 Mon Sep 17 00:00:00 2001 From: Tomas Date: Fri, 12 Jan 2024 10:48:34 +0200 Subject: [PATCH] Support proximityPrecision setting --- src/DependencyInjection/Configuration.php | 8 ++++-- src/Services/SettingsUpdater.php | 2 +- tests/Unit/ConfigurationTest.php | 34 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 9342e27b..91cb422b 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -64,8 +64,12 @@ public function getConfigTreeBuilder(): TreeBuilder ->beforeNormalization() ->always() ->then(static function (array $value) { - if (isset($value['distinctAttribute']) && !is_array($value['distinctAttribute'])) { - $value['distinctAttribute'] = (array) $value['distinctAttribute']; + $stringSettings = ['distinctAttribute', 'proximityPrecision']; + + foreach ($stringSettings as $setting) { + if (isset($value[$setting]) && !is_array($value[$setting])) { + $value[$setting] = (array) $value[$setting]; + } } return $value; diff --git a/src/Services/SettingsUpdater.php b/src/Services/SettingsUpdater.php index 680286e7..8584d542 100644 --- a/src/Services/SettingsUpdater.php +++ b/src/Services/SettingsUpdater.php @@ -58,7 +58,7 @@ public function update(string $indice, ?int $responseTimeout = null): void if (isset($value['_service']) && $value['_service'] instanceof SettingsProvider) { $value = $value['_service'](); - } elseif ('distinctAttribute' === $variable && is_array($value)) { + } elseif (('distinctAttribute' === $variable || 'proximityPrecision' === $variable) && is_array($value)) { $value = $value[0] ?? null; } diff --git a/tests/Unit/ConfigurationTest.php b/tests/Unit/ConfigurationTest.php index bdbb187b..fca71a73 100644 --- a/tests/Unit/ConfigurationTest.php +++ b/tests/Unit/ConfigurationTest.php @@ -214,6 +214,40 @@ public function dataTestConfigurationTree(): array 'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'], ], ], + 'proximity precision' => [ + [ + 'prefix' => 'sf_', + 'indices' => [ + [ + 'name' => 'items', + 'class' => 'App\Entity\Post', + 'settings' => [ + 'proximityPrecision' => 'byWord', + ], + ], + ], + ], + [ + 'url' => 'http://localhost:7700', + 'prefix' => 'sf_', + 'indices' => [ + [ + 'name' => 'items', + 'class' => 'App\Entity\Post', + 'enable_serializer_groups' => false, + 'serializer_groups' => ['searchable'], + 'index_if' => null, + 'settings' => [ + 'proximityPrecision' => ['byWord'], + ], + ], + ], + 'nbResults' => 20, + 'batchSize' => 500, + 'serializer' => 'serializer', + 'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'], + ], + ], ]; } }