From 17c8c6f945bdffebdf6a935160566f9e6deaa8be Mon Sep 17 00:00:00 2001 From: many Date: Tue, 6 Apr 2021 15:03:41 +0200 Subject: [PATCH] Make set algorithm return None when nothing can be returned --- milli/src/search/criteria/attribute.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/milli/src/search/criteria/attribute.rs b/milli/src/search/criteria/attribute.rs index d96ec493f..12c6b36b8 100644 --- a/milli/src/search/criteria/attribute.rs +++ b/milli/src/search/criteria/attribute.rs @@ -71,7 +71,18 @@ impl<'t> Criterion for Attribute<'t> { }, } } else { - set_compute_candidates(self.ctx, flattened_query_tree, candidates, wdcache)? + let found_candidates = set_compute_candidates(self.ctx, flattened_query_tree, candidates, wdcache)?; + + match found_candidates { + Some(candidates) => candidates, + None => { + return Ok(Some(CriterionResult { + query_tree: self.query_tree.take(), + candidates: self.candidates.take(), + bucket_candidates: take(&mut self.bucket_candidates), + })); + }, + } }; candidates.difference_with(&found_candidates); @@ -414,11 +425,11 @@ fn set_compute_candidates<'t>( branches: &Vec>>, allowed_candidates: &RoaringBitmap, wdcache: &mut WordDerivationsCache, -) -> anyhow::Result +) -> anyhow::Result> { let mut branches_heap = initialize_query_level_iterators(ctx, branches, wdcache)?; let lowest_level = TreeLevel::min_value(); - let mut final_candidates = RoaringBitmap::new(); + let mut final_candidates = None; while let Some(mut branch) = branches_heap.peek_mut() { let is_lowest_level = branch.tree_level == lowest_level; @@ -427,7 +438,7 @@ fn set_compute_candidates<'t>( candidates.intersect_with(&allowed_candidates); if candidates.len() > 0 && is_lowest_level { // we have candidates, but we can't dig deeper, return candidates. - final_candidates = std::mem::take(candidates); + final_candidates = Some(std::mem::take(candidates)); break; } else if candidates.len() > 0 { // we have candidates, lets dig deeper in levels.