diff --git a/milli/src/search/criteria/mod.rs b/milli/src/search/criteria/mod.rs index d21102e64..45689bbe5 100644 --- a/milli/src/search/criteria/mod.rs +++ b/milli/src/search/criteria/mod.rs @@ -10,7 +10,17 @@ use super::query_tree::{Operation, Query, QueryKind}; pub mod typo; pub trait Criterion { - fn next(&mut self) -> anyhow::Result, RoaringBitmap)>>; + fn next(&mut self) -> anyhow::Result>; +} + +/// The result of a call to the parent criterion. +pub struct CriterionResult { + /// The query tree that must be used by the children criterion to fetch candidates. + pub query_tree: Option, + /// 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, } /// 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 9834bbc21..781ea1ec8 100644 --- a/milli/src/search/criteria/typo.rs +++ b/milli/src/search/criteria/typo.rs @@ -5,7 +5,7 @@ use roaring::RoaringBitmap; use crate::search::query_tree::{Operation, Query, QueryKind}; use crate::search::word_typos; -use super::{Candidates, Criterion, Context}; +use super::{Candidates, Criterion, CriterionResult, Context}; // FIXME we must stop when the number of typos is equal to // the maximum number of typos for this query tree. @@ -51,7 +51,7 @@ impl<'t> Typo<'t> { } impl<'t> Criterion for Typo<'t> { - fn next(&mut self) -> anyhow::Result, RoaringBitmap)>> { + fn next(&mut self) -> anyhow::Result> { use Candidates::{Allowed, Forbidden}; while self.number_typos < MAX_NUM_TYPOS { match (&mut self.query_tree, &mut self.candidates) { @@ -68,7 +68,11 @@ impl<'t> Criterion for Typo<'t> { candidates.difference_with(&new_candidates); self.number_typos += 1; - return Ok(Some((Some(new_query_tree), new_candidates))); + return Ok(Some(CriterionResult { + query_tree: Some(new_query_tree), + candidates: new_candidates, + bucket_candidates: None, + })); }, (Some(query_tree), Forbidden(candidates)) => { // TODO if number_typos >= 2 the generated query_tree will allways be the same, @@ -79,16 +83,24 @@ impl<'t> Criterion for Typo<'t> { candidates.union_with(&new_candidates); self.number_typos += 1; - return Ok(Some((Some(new_query_tree), new_candidates))); + return Ok(Some(CriterionResult { + query_tree: Some(new_query_tree), + candidates: new_candidates, + bucket_candidates: None, + })); }, (None, Allowed(_)) => { - return Ok(Some((None, take(&mut self.candidates).into_inner()))); + return Ok(Some(CriterionResult { + query_tree: None, + candidates: take(&mut self.candidates).into_inner(), + bucket_candidates: None, + })); }, (None, Forbidden(_)) => { match self.parent.as_mut() { Some(parent) => { match parent.next()? { - Some((query_tree, candidates)) => { + Some(CriterionResult { query_tree, candidates, .. }) => { self.query_tree = query_tree; self.candidates = Candidates::Allowed(candidates); }, diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index d061df2b9..89abb01b4 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -18,7 +18,7 @@ use crate::heed_codec::facet::{FacetLevelValueF64Codec, FacetLevelValueI64Codec} use crate::heed_codec::facet::{FieldDocIdFacetF64Codec, FieldDocIdFacetI64Codec}; use crate::mdfs::Mdfs; use crate::query_tokens::{query_tokens, QueryToken}; -use crate::search::criteria::Criterion; +use crate::search::criteria::{Criterion, CriterionResult}; use crate::search::criteria::typo::Typo; use crate::{Index, FieldId, DocumentId}; @@ -294,7 +294,7 @@ impl<'a> Search<'a> { let mut offset = self.offset; let mut limit = self.limit; let mut documents_ids = Vec::new(); - while let Some((_qt, docids)) = criteria.next()? { + while let Some(CriterionResult { candidates: docids, .. }) = criteria.next()? { let mut len = docids.len() as usize; let mut docids = docids.into_iter();