Skip to content

Commit 17acb3c

Browse files
committed
Support proximityPrecision setting
1 parent b896111 commit 17acb3c

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ public function getConfigTreeBuilder(): TreeBuilder
6464
->beforeNormalization()
6565
->always()
6666
->then(static function (array $value) {
67-
if (isset($value['distinctAttribute']) && !is_array($value['distinctAttribute'])) {
68-
$value['distinctAttribute'] = (array) $value['distinctAttribute'];
67+
$stringSettings = ['distinctAttribute', 'proximityPrecision'];
68+
69+
foreach ($stringSettings as $setting) {
70+
if (isset($value[$setting]) && !is_array($value[$setting])) {
71+
$value[$setting] = (array) $value[$setting];
72+
}
6973
}
7074

7175
return $value;

src/Services/SettingsUpdater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function update(string $indice, ?int $responseTimeout = null): void
5858

5959
if (isset($value['_service']) && $value['_service'] instanceof SettingsProvider) {
6060
$value = $value['_service']();
61-
} elseif ('distinctAttribute' === $variable && is_array($value)) {
61+
} elseif (('distinctAttribute' === $variable || 'proximityPrecision' === $variable) && is_array($value)) {
6262
$value = $value[0] ?? null;
6363
}
6464

tests/Unit/ConfigurationTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,40 @@ public function dataTestConfigurationTree(): array
214214
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
215215
],
216216
],
217+
'proximity precision' => [
218+
[
219+
'prefix' => 'sf_',
220+
'indices' => [
221+
[
222+
'name' => 'items',
223+
'class' => 'App\Entity\Post',
224+
'settings' => [
225+
'proximityPrecision' => 'byWord',
226+
],
227+
],
228+
],
229+
],
230+
[
231+
'url' => 'http://localhost:7700',
232+
'prefix' => 'sf_',
233+
'indices' => [
234+
[
235+
'name' => 'items',
236+
'class' => 'App\Entity\Post',
237+
'enable_serializer_groups' => false,
238+
'serializer_groups' => ['searchable'],
239+
'index_if' => null,
240+
'settings' => [
241+
'proximityPrecision' => ['byWord'],
242+
],
243+
],
244+
],
245+
'nbResults' => 20,
246+
'batchSize' => 500,
247+
'serializer' => 'serializer',
248+
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
249+
],
250+
],
217251
];
218252
}
219253
}

0 commit comments

Comments
 (0)