From 77f1ff019b59efb78057270e6b6c56de7081f9ea Mon Sep 17 00:00:00 2001 From: Samyak S Sarnayak Date: Thu, 20 Oct 2022 18:35:39 +0530 Subject: [PATCH] Simplify stop word checking in create_primitive_query --- milli/src/search/query_tree.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/milli/src/search/query_tree.rs b/milli/src/search/query_tree.rs index 25366461c..5042f4762 100755 --- a/milli/src/search/query_tree.rs +++ b/milli/src/search/query_tree.rs @@ -4,7 +4,6 @@ use std::{fmt, mem}; use charabia::classifier::ClassifiedTokenIter; use charabia::{SeparatorKind, TokenKind}; -use fst::Set; use roaring::RoaringBitmap; use slice_group_by::GroupBy; @@ -269,8 +268,7 @@ impl<'a> QueryTreeBuilder<'a> { &self, query: ClassifiedTokenIter, ) -> Result> { - let stop_words = self.index.stop_words(self.rtxn)?; - let primitive_query = create_primitive_query(query, stop_words, self.words_limit); + let primitive_query = create_primitive_query(query, self.words_limit); if !primitive_query.is_empty() { let qt = create_query_tree( self, @@ -722,7 +720,6 @@ impl PrimitiveQueryPart { /// the primitive query is an intermediate state to build the query tree. fn create_primitive_query( query: ClassifiedTokenIter, - stop_words: Option>, words_limit: Option, ) -> PrimitiveQuery where @@ -747,13 +744,14 @@ where // 2. if the word is not the last token of the query and is not a stop_word we push it as a non-prefix word, // 3. if the word is the last token of the query we push it as a prefix word. if quoted { - if stop_words.as_ref().map_or(false, |swords| swords.contains(token.lemma())) { + if let TokenKind::StopWord = token.kind { phrase.push(None) } else { phrase.push(Some(token.lemma().to_string())); } } else if peekable.peek().is_some() { - if !stop_words.as_ref().map_or(false, |swords| swords.contains(token.lemma())) { + if let TokenKind::StopWord = token.kind { + } else { primitive_query .push(PrimitiveQueryPart::Word(token.lemma().to_string(), false)); } @@ -836,7 +834,7 @@ mod test { words_limit: Option, query: ClassifiedTokenIter, ) -> Result> { - let primitive_query = create_primitive_query(query, None, words_limit); + let primitive_query = create_primitive_query(query, words_limit); if !primitive_query.is_empty() { let qt = create_query_tree( self,