From 6d135beb21ab9bfcc9cd5bce0ed52e381b0f5031 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 23 Feb 2021 15:53:24 +0100 Subject: [PATCH] Introduce the maximum_proximity 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 1aaacbccb..64babe053 100644 --- a/milli/src/search/query_tree.rs +++ b/milli/src/search/query_tree.rs @@ -524,6 +524,16 @@ pub fn maximum_typo(operation: &Operation) -> usize { } } +/// Returns the maximum proximity that this Operation allows. +pub fn maximum_proximity(operation: &Operation) -> usize { + use Operation::{Or, And, Query, Consecutive}; + match operation { + Or(_, ops) => ops.iter().map(maximum_proximity).max().unwrap_or(0), + And(ops) => ops.len().saturating_sub(1) * 8, + Query(_) | Consecutive(_) => 0, + } +} + #[cfg(test)] mod test { use fst::Set;