From cdaa96df6329670cf959ebb67c5e86618e1bfaea Mon Sep 17 00:00:00 2001 From: many Date: Tue, 2 Mar 2021 14:46:50 +0100 Subject: [PATCH] optimize proximity criterion --- milli/src/search/criteria/proximity.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/milli/src/search/criteria/proximity.rs b/milli/src/search/criteria/proximity.rs index 553a191ec..dc05787dd 100644 --- a/milli/src/search/criteria/proximity.rs +++ b/milli/src/search/criteria/proximity.rs @@ -205,14 +205,16 @@ fn resolve_candidates<'t>( cache: &mut HashMap<(Operation, u8), Vec<(Query, Query, RoaringBitmap)>>, ) -> anyhow::Result> { - fn pair_combinations(mana: u8) -> impl Iterator { - (0..=mana).map(move |m| (mana - m, m)) + fn pair_combinations(mana: u8, left_max: u8) -> impl Iterator { + (0..=mana.min(left_max)).map(move |m| (m, mana - m)) } + let pair_max_proximity = 7; + let mut output = Vec::new(); - for (pair_p, left_right_p) in pair_combinations(proximity) { - for (left_p, right_p) in pair_combinations(left_right_p) { + for (pair_p, left_right_p) in pair_combinations(proximity, pair_max_proximity) { + for (left_p, right_p) in pair_combinations(left_right_p, left_right_p) { let left_key = (left.clone(), left_p); if !cache.contains_key(&left_key) { let candidates = resolve_operation(ctx, left, left_p, cache)?;