Skip to content

Commit 411c953

Browse files
Merge #295
295: Fix using distinct attribute setting r=brunoocasali a=norkunas # Pull Request ## Related issue Fixes #273 ## What does this PR do? - Fixes updating distinct attribute setting and allows to set it as a string instead of an array ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Temporary fix until we'll provide proper configuration schema for each setting separately. Co-authored-by: Tomas <[email protected]>
2 parents 6691a3f + 75fcb7c commit 411c953

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

src/Command/MeilisearchCreateCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9292

9393
if (isset($value['_service']) && $value['_service'] instanceof SettingsProvider) {
9494
$value = $value['_service']();
95+
} elseif ('distinctAttribute' === $variable && is_array($value)) {
96+
$value = $value[0] ?? null;
9597
}
9698

9799
// Update

src/Command/MeilisearchImportCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
161161

162162
if (isset($value['_service']) && $value['_service'] instanceof SettingsProvider) {
163163
$value = $value['_service']();
164+
} elseif ('distinctAttribute' === $variable && is_array($value)) {
165+
$value = $value[0] ?? null;
164166
}
165167

166168
// Update

src/DependencyInjection/Configuration.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ public function getConfigTreeBuilder(): TreeBuilder
6161
->end()
6262
->arrayNode('settings')
6363
->info('Configure indices settings, see: https://www.meilisearch.com/docs/reference/api/settings')
64+
->beforeNormalization()
65+
->always()
66+
->then(static function (array $value) {
67+
if (isset($value['distinctAttribute']) && !is_array($value['distinctAttribute'])) {
68+
$value['distinctAttribute'] = (array) $value['distinctAttribute'];
69+
}
70+
71+
return $value;
72+
})
73+
->end()
6474
->arrayPrototype()
6575
->variablePrototype()->end()
6676
->end()

tests/Unit/ConfigurationTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,40 @@ public function dataTestConfigurationTree(): array
180180
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
181181
],
182182
],
183+
'distinct attribute' => [
184+
[
185+
'prefix' => 'sf_',
186+
'indices' => [
187+
[
188+
'name' => 'items',
189+
'class' => 'App\Entity\Post',
190+
'settings' => [
191+
'distinctAttribute' => 'product_id',
192+
],
193+
],
194+
],
195+
],
196+
[
197+
'url' => 'http://localhost:7700',
198+
'prefix' => 'sf_',
199+
'indices' => [
200+
[
201+
'name' => 'items',
202+
'class' => 'App\Entity\Post',
203+
'enable_serializer_groups' => false,
204+
'serializer_groups' => ['searchable'],
205+
'index_if' => null,
206+
'settings' => [
207+
'distinctAttribute' => ['product_id'],
208+
],
209+
],
210+
],
211+
'nbResults' => 20,
212+
'batchSize' => 500,
213+
'serializer' => 'serializer',
214+
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
215+
],
216+
],
183217
];
184218
}
185219
}

0 commit comments

Comments
 (0)