mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-30 00:34:26 +01:00
optimize alterate_query_tree when number_typos is zero
This commit is contained in:
parent
4da6e1ea9c
commit
41fc51ebcf
@ -171,19 +171,27 @@ fn alterate_query_tree(
|
|||||||
ops.iter_mut().try_for_each(|op| recurse(words_fst, op, number_typos))
|
ops.iter_mut().try_for_each(|op| recurse(words_fst, op, number_typos))
|
||||||
},
|
},
|
||||||
Operation::Query(q) => {
|
Operation::Query(q) => {
|
||||||
// TODO may be optimized when number_typos == 0
|
|
||||||
if let QueryKind::Tolerant { typo, word } = &q.kind {
|
if let QueryKind::Tolerant { typo, word } = &q.kind {
|
||||||
let typo = *typo.min(&number_typos);
|
// if no typo is allowed we don't call word_typos(..),
|
||||||
let words = word_typos(word, q.prefix, typo, words_fst)?;
|
// 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)?;
|
||||||
|
|
||||||
let queries = words.into_iter().map(|(word, _typo)| {
|
let queries = words.into_iter().map(|(word, _typo)| {
|
||||||
Operation::Query(Query {
|
Operation::Query(Query {
|
||||||
prefix: false,
|
prefix: false,
|
||||||
kind: QueryKind::Exact { original_typo: typo, word },
|
kind: QueryKind::Exact { original_typo: typo, word },
|
||||||
})
|
})
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
*operation = Operation::or(false, queries);
|
*operation = Operation::or(false, queries);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user