@@ -39,19 +39,24 @@ impl<D: Distinct> Criterion for Initial<'_, D> {
3939 self . answer
4040 . take ( )
4141 . map ( |mut answer| {
42- if self . exhaustive_number_hits && answer . query_tree . is_some ( ) {
42+ if self . exhaustive_number_hits {
4343 // resolve the whole query tree to retrieve an exhaustive list of documents matching the query.
44- // then remove the potential soft deleted documents.
45- let mut candidates = resolve_query_tree (
46- self . ctx ,
47- answer. query_tree . as_ref ( ) . unwrap ( ) ,
48- params. wdcache ,
49- ) ? - params. excluded_candidates ;
44+ let candidates = answer
45+ . query_tree
46+ . as_ref ( )
47+ . map ( |query_tree| resolve_query_tree ( self . ctx , query_tree, params. wdcache ) )
48+ . transpose ( ) ?;
49+
50+ // then intersect the candidates with the potential filtered candidates.
51+ let mut candidates = match ( candidates, answer. filtered_candidates . take ( ) ) {
52+ ( Some ( candidates) , Some ( filtered) ) => candidates & filtered,
53+ ( Some ( candidates) , None ) => candidates,
54+ ( None , Some ( filtered) ) => filtered,
55+ ( None , None ) => self . ctx . documents_ids ( ) ?,
56+ } ;
5057
51- // Apply the filters on the documents retrieved with the query tree.
52- if let Some ( ref filtered_candidates) = answer. filtered_candidates {
53- candidates &= filtered_candidates;
54- }
58+ // then remove the potential soft deleted documents.
59+ candidates -= params. excluded_candidates ;
5560
5661 // because the initial_candidates should be an exhaustive count of the matching documents,
5762 // we precompute the distinct attributes.
0 commit comments