Better support space around the negative operator (-)

This commit is contained in:
Clément Renault 2024-03-26 17:42:09 +01:00
parent e4a3e603b3
commit 1da9e0f246
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F

View File

@ -21,6 +21,7 @@ pub fn located_query_terms_from_tokens(
let mut located_terms = Vec::new();
let mut phrase: Option<PhraseBuilder> = None;
let mut encountered_whitespace = true;
let mut negative_next_token = false;
let mut negative_words = Vec::new();
@ -34,6 +35,7 @@ pub fn located_query_terms_from_tokens(
if token.lemma().is_empty() {
continue;
}
// early return if word limit is exceeded
if located_terms.len() >= parts_limit {
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())
};
if phrase.is_none() && token.lemma() == "-" {
negative_next_token = true;
}
negative_next_token =
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.