From 6008f528d05e59e61158c35c8841f44627593646 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 23 Feb 2021 15:50:33 +0100 Subject: [PATCH] Introduce the maximum_typo helper function --- milli/src/search/query_tree.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) 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;