diff --git a/milli/src/search/query_tree.rs b/milli/src/search/query_tree.rs index 682f66f24..1aaacbccb 100644 --- a/milli/src/search/query_tree.rs +++ b/milli/src/search/query_tree.rs @@ -514,6 +514,16 @@ fn create_primitive_query(query: TokenStream) -> PrimitiveQuery { primitive_query } +/// Returns the maximum number of typos that this Operation allows. +pub fn maximum_typo(operation: &Operation) -> usize { + use Operation::{Or, And, Query, Consecutive}; + match operation { + Or(_, ops) => ops.iter().map(maximum_typo).max().unwrap_or(0), + And(ops) | Consecutive(ops) => ops.iter().map(maximum_typo).sum::(), + Query(q) => q.kind.typo() as usize, + } +} + #[cfg(test)] mod test { use fst::Set;