Add stop words on query

This commit is contained in:
qdequele 2020-02-10 16:50:55 +01:00
parent dc6907e748
commit 559c2f8907
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
3 changed files with 11 additions and 0 deletions

View File

@ -69,8 +69,11 @@ where
None => return Ok(Vec::new()),
};
let stop_words = main_store.stop_words_fst(reader)?.unwrap_or_default();
let context = QTContext {
words_set,
stop_words,
synonyms: synonyms_store,
postings_lists: postings_lists_store,
prefix_postings_lists: prefix_postings_lists_cache_store,
@ -198,8 +201,11 @@ where
None => return Ok(Vec::new()),
};
let stop_words = main_store.stop_words_fst(reader)?.unwrap_or_default();
let context = QTContext {
words_set,
stop_words,
synonyms: synonyms_store,
postings_lists: postings_lists_store,
prefix_postings_lists: prefix_postings_lists_cache_store,

View File

@ -114,6 +114,7 @@ pub struct PostingsList {
pub struct Context {
pub words_set: fst::Set,
pub stop_words: fst::Set,
pub synonyms: store::Synonyms,
pub postings_lists: store::PostingsLists,
pub prefix_postings_lists: store::PrefixPostingsListsCache,
@ -180,6 +181,7 @@ pub fn create_query_tree(
) -> MResult<(Operation, HashMap<QueryId, Range<usize>>)>
{
let words = split_query_string(query).map(str::to_lowercase);
let words = words.filter(|w| !ctx.stop_words.contains(w));
let words: Vec<_> = words.enumerate().collect();
let mut mapper = QueryWordsMapper::new(words.iter().map(|(_, w)| w));

View File

@ -171,6 +171,9 @@ pub fn apply_stop_words_update(
)?;
return Ok(true)
}
let stop_words_fst = fst::Set::from_iter(stop_words)?;
index.main.put_words_fst(writer, &stop_words_fst)?;
Ok(false)
}