mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-10-26 05:26:27 +00:00 
			
		
		
		
	Better support space around the negative operator (-)
This commit is contained in:
		| @@ -21,6 +21,7 @@ pub fn located_query_terms_from_tokens( | |||||||
|     let mut located_terms = Vec::new(); |     let mut located_terms = Vec::new(); | ||||||
|  |  | ||||||
|     let mut phrase: Option<PhraseBuilder> = None; |     let mut phrase: Option<PhraseBuilder> = None; | ||||||
|  |     let mut encountered_whitespace = true; | ||||||
|     let mut negative_next_token = false; |     let mut negative_next_token = false; | ||||||
|     let mut negative_words = Vec::new(); |     let mut negative_words = Vec::new(); | ||||||
|  |  | ||||||
| @@ -34,6 +35,7 @@ pub fn located_query_terms_from_tokens( | |||||||
|         if token.lemma().is_empty() { |         if token.lemma().is_empty() { | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // early return if word limit is exceeded |         // early return if word limit is exceeded | ||||||
|         if located_terms.len() >= parts_limit { |         if located_terms.len() >= parts_limit { | ||||||
|             return Ok((located_terms, negative_words)); |             return Ok((located_terms, negative_words)); | ||||||
| @@ -131,12 +133,14 @@ pub fn located_query_terms_from_tokens( | |||||||
|                     (quote_count % 2 == 1).then_some(PhraseBuilder::empty()) |                     (quote_count % 2 == 1).then_some(PhraseBuilder::empty()) | ||||||
|                 }; |                 }; | ||||||
|  |  | ||||||
|                 if phrase.is_none() && token.lemma() == "-" { |                 negative_next_token = | ||||||
|                     negative_next_token = true; |                     phrase.is_none() && token.lemma() == "-" && encountered_whitespace; | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|             _ => (), |             _ => (), | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         encountered_whitespace = | ||||||
|  |             token.lemma().chars().last().filter(|c| c.is_whitespace()).is_some(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // If a quote is never closed, we consider all of the end of the query as a phrase. |     // If a quote is never closed, we consider all of the end of the query as a phrase. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user