optimize alterate_query_tree when number_typos is zero

This commit is contained in:
many 2021-02-18 15:08:56 +01:00 committed by Kerollmops
parent 4da6e1ea9c
commit 41fc51ebcf
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -171,8 +171,15 @@ fn alterate_query_tree(
ops.iter_mut().try_for_each(|op| recurse(words_fst, op, number_typos))
},
Operation::Query(q) => {
// TODO may be optimized when number_typos == 0
if let QueryKind::Tolerant { typo, word } = &q.kind {
// if no typo is allowed we don't call word_typos(..),
// and directly create an Exact query
if number_typos == 0 {
*operation = Operation::Query(Query {
prefix: q.prefix,
kind: QueryKind::Exact { original_typo: 0, word: word.clone() },
});
} else {
let typo = *typo.min(&number_typos);
let words = word_typos(word, q.prefix, typo, words_fst)?;
@ -185,6 +192,7 @@ fn alterate_query_tree(
*operation = Operation::or(false, queries);
}
}
Ok(())
},