From d92ad5640ae188ace90517687fedea5041c48bc1 Mon Sep 17 00:00:00 2001 From: many Date: Thu, 25 Feb 2021 16:14:38 +0100 Subject: [PATCH] remove option on bucket_candidates --- milli/src/search/criteria/mod.rs | 2 +- milli/src/search/criteria/typo.rs | 30 +++++++++++++++--------------- milli/src/search/mod.rs | 4 +--- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/milli/src/search/criteria/mod.rs b/milli/src/search/criteria/mod.rs index 77d92f6ea..e7549cae1 100644 --- a/milli/src/search/criteria/mod.rs +++ b/milli/src/search/criteria/mod.rs @@ -21,7 +21,7 @@ pub struct CriterionResult { /// The candidates that this criterion is allowed to return subsets of. pub candidates: RoaringBitmap, /// Candidates that comes from the current bucket of the initial criterion. - pub bucket_candidates: Option, + pub bucket_candidates: RoaringBitmap, } /// Either a set of candidates that defines the candidates diff --git a/milli/src/search/criteria/typo.rs b/milli/src/search/criteria/typo.rs index d9a5f8aa6..a9d3b5d96 100644 --- a/milli/src/search/criteria/typo.rs +++ b/milli/src/search/criteria/typo.rs @@ -12,7 +12,7 @@ pub struct Typo<'t> { query_tree: Option<(usize, Operation)>, number_typos: u8, candidates: Candidates, - bucket_candidates: Option, + bucket_candidates: RoaringBitmap, parent: Option>, candidates_cache: HashMap<(Operation, u8), RoaringBitmap>, typo_cache: HashMap<(String, bool, u8), Vec<(String, u8)>>, @@ -30,7 +30,7 @@ impl<'t> Typo<'t> { query_tree: query_tree.map(|op| (maximum_typo(&op), op)), number_typos: 0, candidates: candidates.map_or_else(Candidates::default, Candidates::Allowed), - bucket_candidates: None, + bucket_candidates: RoaringBitmap::new(), parent: None, candidates_cache: HashMap::new(), typo_cache: HashMap::new(), @@ -47,7 +47,7 @@ impl<'t> Typo<'t> { query_tree: None, number_typos: 0, candidates: Candidates::default(), - bucket_candidates: None, + bucket_candidates: RoaringBitmap::new(), parent: Some(parent), candidates_cache: HashMap::new(), typo_cache: HashMap::new(), @@ -85,8 +85,8 @@ impl<'t> Criterion for Typo<'t> { self.number_typos += 1; let bucket_candidates = match self.parent { - Some(_) => self.bucket_candidates.take(), - None => Some(new_candidates.clone()), + Some(_) => take(&mut self.bucket_candidates), + None => new_candidates.clone(), }; return Ok(Some(CriterionResult { @@ -117,8 +117,8 @@ impl<'t> Criterion for Typo<'t> { self.number_typos += 1; let bucket_candidates = match self.parent { - Some(_) => self.bucket_candidates.take(), - None => Some(new_candidates.clone()), + Some(_) => take(&mut self.bucket_candidates), + None => new_candidates.clone(), }; return Ok(Some(CriterionResult { @@ -133,7 +133,7 @@ impl<'t> Criterion for Typo<'t> { return Ok(Some(CriterionResult { query_tree: None, candidates: candidates.clone(), - bucket_candidates: Some(candidates), + bucket_candidates: candidates, })); }, (None, Forbidden(_)) => { @@ -373,7 +373,7 @@ mod test { ]), ])), candidates: candidates_1.clone(), - bucket_candidates: Some(candidates_1), + bucket_candidates: candidates_1, }; assert_eq!(criteria.next().unwrap(), Some(expected_1)); @@ -395,7 +395,7 @@ mod test { ]), ])), candidates: candidates_2.clone(), - bucket_candidates: Some(candidates_2), + bucket_candidates: candidates_2, }; assert_eq!(criteria.next().unwrap(), Some(expected_2)); @@ -405,13 +405,13 @@ mod test { fn initial_placeholder_with_facets() { let context = TestContext::default(); let query_tree = None; - let facet_candidates = context.word_docids("earth").unwrap(); + let facet_candidates = context.word_docids("earth").unwrap().unwrap(); - let mut criteria = Typo::initial(&context, query_tree, facet_candidates.clone()).unwrap(); + let mut criteria = Typo::initial(&context, query_tree, Some(facet_candidates.clone())).unwrap(); let expected = CriterionResult { query_tree: None, - candidates: facet_candidates.clone().unwrap(), + candidates: facet_candidates.clone(), bucket_candidates: facet_candidates, }; @@ -449,7 +449,7 @@ mod test { ]), ])), candidates: &candidates_1 & &facet_candidates, - bucket_candidates: Some(candidates_1 & &facet_candidates), + bucket_candidates: candidates_1 & &facet_candidates, }; assert_eq!(criteria.next().unwrap(), Some(expected_1)); @@ -471,7 +471,7 @@ mod test { ]), ])), candidates: &candidates_2 & &facet_candidates, - bucket_candidates: Some(candidates_2 & &facet_candidates), + bucket_candidates: candidates_2 & &facet_candidates, }; assert_eq!(criteria.next().unwrap(), Some(expected_2)); diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index 1e3e8eefe..7a8bbdc09 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -100,9 +100,7 @@ impl<'a> Search<'a> { let mut len = candidates.len() as usize; let mut candidates = candidates.into_iter(); - if let Some(docids) = bucket_candidates { - initial_candidates.union_with(&docids); - } + initial_candidates.union_with(&bucket_candidates); if offset != 0 { candidates.by_ref().skip(offset).for_each(drop);