From 3322018c066824ac5a112a3abf258c9dda78d77f Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Wed, 14 Dec 2022 20:09:47 +0100 Subject: [PATCH] Fix placeholder search --- milli/src/search/criteria/initial.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/milli/src/search/criteria/initial.rs b/milli/src/search/criteria/initial.rs index 44c08dc06..0826a9f68 100644 --- a/milli/src/search/criteria/initial.rs +++ b/milli/src/search/criteria/initial.rs @@ -39,19 +39,24 @@ impl Criterion for Initial<'_, D> { self.answer .take() .map(|mut answer| { - if self.exhaustive_number_hits && answer.query_tree.is_some() { + if self.exhaustive_number_hits { // resolve the whole query tree to retrieve an exhaustive list of documents matching the query. - // then remove the potential soft deleted documents. - let mut candidates = resolve_query_tree( - self.ctx, - answer.query_tree.as_ref().unwrap(), - params.wdcache, - )? - params.excluded_candidates; + let candidates = answer + .query_tree + .as_ref() + .map(|query_tree| resolve_query_tree(self.ctx, query_tree, params.wdcache)) + .transpose()?; - // Apply the filters on the documents retrieved with the query tree. - if let Some(ref filtered_candidates) = answer.filtered_candidates { - candidates &= filtered_candidates; - } + // then intersect the candidates with the potential filtered candidates. + let mut candidates = match (candidates, answer.filtered_candidates.take()) { + (Some(candidates), Some(filtered)) => candidates & filtered, + (Some(candidates), None) => candidates, + (None, Some(filtered)) => filtered, + (None, None) => self.ctx.documents_ids()?, + }; + + // then remove the potential soft deleted documents. + candidates -= params.excluded_candidates; // because the initial_candidates should be an exhaustive count of the matching documents, // we precompute the distinct attributes.