From ae4a237e580a38b930c8422297b275cb08819aac Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 24 Feb 2021 15:36:57 +0100 Subject: [PATCH] Fix the maximum_proximity function --- milli/src/search/criteria/mod.rs | 8 +++++++- milli/src/search/query_tree.rs | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/milli/src/search/criteria/mod.rs b/milli/src/search/criteria/mod.rs index 41cd6722c..52367ac5f 100644 --- a/milli/src/search/criteria/mod.rs +++ b/milli/src/search/criteria/mod.rs @@ -153,8 +153,14 @@ fn query_docids(ctx: &dyn Context, query: &Query) -> anyhow::Result anyhow::Result { - let prefix = right.prefix; + if proximity >= 8 { + let mut candidates = query_docids(ctx, left)?; + let right_candidates = query_docids(ctx, right)?; + candidates.intersect_with(&right_candidates); + return Ok(candidates); + } + let prefix = right.prefix; match (&left.kind, &right.kind) { (QueryKind::Exact { word: left, .. }, QueryKind::Exact { word: right, .. }) => { if prefix && ctx.in_prefix_cache(&right) { diff --git a/milli/src/search/query_tree.rs b/milli/src/search/query_tree.rs index 59f7802f3..47057ad10 100644 --- a/milli/src/search/query_tree.rs +++ b/milli/src/search/query_tree.rs @@ -546,7 +546,10 @@ 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, + And(ops) => { + ops.iter().map(maximum_proximity).sum::() + + ops.len().saturating_sub(1) * 7 + }, Query(_) | Consecutive(_) => 0, } }