From 73093bde9df022b4572a184e5b72ab1c063d3572 Mon Sep 17 00:00:00 2001 From: Richard BAYET Date: Tue, 8 Oct 2024 11:17:39 +0200 Subject: [PATCH] [Core] No edge ngram decomposition in termVectors To avoid false 'exact' matches on leading parts of a misspelled word. The logic is similar to the use of a distinct 'search_analyzer' on fields using 'standard_edge_ngram' as 'analyzer'. --- .../Search/Adapter/Elasticsuite/Spellchecker.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Spellchecker.php b/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Spellchecker.php index d324ab5e9..a284a9628 100644 --- a/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Spellchecker.php +++ b/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Spellchecker.php @@ -164,6 +164,7 @@ private function getTermVectors(RequestInterface $request) MappingInterface::DEFAULT_SPELLING_FIELD => $request->getQueryText(), ], ]; + $perFieldAnalyzer = []; if ($request->isUsingReference()) { $doc['fields'][] = MappingInterface::DEFAULT_REFERENCE_FIELD . "." . FieldInterface::ANALYZER_REFERENCE; @@ -172,9 +173,15 @@ private function getTermVectors(RequestInterface $request) if ($request->isUsingEdgeNgram()) { $doc['fields'][] = MappingInterface::DEFAULT_EDGE_NGRAM_FIELD . "." . FieldInterface::ANALYZER_EDGE_NGRAM; + $perFieldAnalyzer[MappingInterface::DEFAULT_EDGE_NGRAM_FIELD . "." . FieldInterface::ANALYZER_EDGE_NGRAM] + = FieldInterface::ANALYZER_STANDARD; $doc['doc'][MappingInterface::DEFAULT_EDGE_NGRAM_FIELD] = $request->getQueryText(); } + if (!empty($perFieldAnalyzer)) { + $doc['per_field_analyzer'] = $perFieldAnalyzer; + } + $docs = []; // Compute the mtermvector query on all indices.