From b5df889dcb3db58e6c06c27103f5c9cda7d02974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Mon, 2 Jan 2023 10:46:35 +0100 Subject: [PATCH] Apply review suggestions: simplify implementation of exactness criterion --- milli/src/search/criteria/exactness.rs | 39 ++++++++------------------ 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/milli/src/search/criteria/exactness.rs b/milli/src/search/criteria/exactness.rs index 29e8ce87a..d4a90576c 100644 --- a/milli/src/search/criteria/exactness.rs +++ b/milli/src/search/criteria/exactness.rs @@ -191,7 +191,7 @@ fn resolve_state( attribute_start_with_docids(ctx, id, query)?; attribute_candidates_array.push(attribute_allowed_docids); - candidates |= intersection_of(attribute_candidates_array.iter().collect()); + candidates |= MultiOps::intersection(attribute_candidates_array); } } @@ -208,7 +208,7 @@ fn resolve_state( let attributes_ids = ctx.searchable_fields_ids()?; for id in attributes_ids { let attribute_candidates_array = attribute_start_with_docids(ctx, id, query)?; - candidates |= intersection_of(attribute_candidates_array.iter().collect()); + candidates |= MultiOps::intersection(attribute_candidates_array); } // only keep allowed candidates @@ -289,12 +289,6 @@ fn attribute_start_with_docids( Ok(attribute_candidates_array) } -#[inline(never)] -fn intersection_of(mut rbs: Vec<&RoaringBitmap>) -> RoaringBitmap { - rbs.sort_unstable_by_key(|rb| rb.len()); - roaring::MultiOps::intersection(rbs.into_iter()) -} - #[derive(Debug, Clone)] pub enum ExactQueryPart { Phrase(Vec>), @@ -440,8 +434,7 @@ fn compute_combinations( fn create_non_disjoint_combinations(bitmaps: Vec) -> Vec { let nbr_parts = bitmaps.len(); if nbr_parts == 1 { - let flattened_base_level = MultiOps::union(bitmaps.into_iter()); - return vec![flattened_base_level]; + return bitmaps; } let mut flattened_levels = vec![]; let mut last_level: BTreeMap = @@ -466,12 +459,12 @@ fn create_non_disjoint_combinations(bitmaps: Vec) -> Vec) -> Vec) -> Vec { let non_disjoint_combinations = create_non_disjoint_combinations(parts_candidates_array); - let mut disjoint_combinations = vec![]; - let mut forbidden = RoaringBitmap::new(); - for mut combination in non_disjoint_combinations.into_iter().rev() { - combination -= &forbidden; - forbidden |= &combination; + let mut combinations = non_disjoint_combinations.into_iter().peekable(); + while let Some(mut combination) = combinations.next() { + if let Some(forbidden) = combinations.peek() { + combination -= forbidden; + } disjoint_combinations.push(combination) } - disjoint_combinations.reverse(); + disjoint_combinations }