From 26e13329da33df6ab1144bb81970f303df64fd5b Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Fri, 19 Apr 2024 14:32:21 +0200 Subject: [PATCH] Fix completion suggesters --- src/Controller/InstantSearchController.php | 20 ++++++++++--------- .../completion-suggesters/query.json.twig | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Controller/InstantSearchController.php b/src/Controller/InstantSearchController.php index eb742fe..3493d07 100644 --- a/src/Controller/InstantSearchController.php +++ b/src/Controller/InstantSearchController.php @@ -71,15 +71,17 @@ public function __invoke(Request $request, string $query): Response private function buildCompletionSuggesters(array $completionSuggesters): array { $suggestions = []; - foreach ($completionSuggesters as $field => $suggestion) { - foreach ($suggestion as $suggestionData) { - $options = $suggestionData['options']; - if (count($options) === 0) { - continue; - } - foreach ($options as $option) { - $suggestions[$field] = $option['text']; - } + foreach ($completionSuggesters as $suggestion) { + $suggestionData = reset($suggestion); + if ($suggestionData === false) { + continue; + } + $options = $suggestionData['options']; + if (count($options) === 0) { + continue; + } + foreach ($options as $option) { + $suggestions[] = $option['text']; } } diff --git a/templates/query/completion-suggesters/query.json.twig b/templates/query/completion-suggesters/query.json.twig index 07e7e2c..ffc67f3 100644 --- a/templates/query/completion-suggesters/query.json.twig +++ b/templates/query/completion-suggesters/query.json.twig @@ -6,7 +6,7 @@ "size": 5, "skip_duplicates": true, "fuzzy": { - "fuzziness": 2, + "fuzziness": 1, "transpositions": true, "min_length": 4 }