From 900bae3d9ddd30bdd501b5d5fabd76e125539df5 Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Tue, 21 Feb 2023 17:52:59 +0100 Subject: [PATCH] keep phrases that has at least one word --- milli/src/search/query_tree.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/milli/src/search/query_tree.rs b/milli/src/search/query_tree.rs index 00c85aaba..431012bdb 100755 --- a/milli/src/search/query_tree.rs +++ b/milli/src/search/query_tree.rs @@ -825,9 +825,13 @@ where quoted = !quoted; } // if there is a quote or a hard separator we close the phrase. - if !phrase.is_empty() && (quote_count > 0 || separator_kind == SeparatorKind::Hard) - { - primitive_query.push(PrimitiveQueryPart::Phrase(mem::take(&mut phrase))); + if quote_count > 0 || separator_kind == SeparatorKind::Hard { + let phrase = mem::take(&mut phrase); + + // if the phrase only contains stop words, we don't keep it in the query. + if phrase.iter().any(|w| w.is_some()) { + primitive_query.push(PrimitiveQueryPart::Phrase(phrase)); + } } } _ => (), @@ -835,7 +839,7 @@ where } // If a quote is never closed, we consider all of the end of the query as a phrase. - if !phrase.is_empty() { + if phrase.iter().any(|w| w.is_some()) { primitive_query.push(PrimitiveQueryPart::Phrase(mem::take(&mut phrase))); }