mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-11 14:04:31 +01:00
Introduce the CriterionResult return type
This commit is contained in:
parent
86bcecf840
commit
5344abc008
@ -10,7 +10,17 @@ use super::query_tree::{Operation, Query, QueryKind};
|
||||
pub mod typo;
|
||||
|
||||
pub trait Criterion {
|
||||
fn next(&mut self) -> anyhow::Result<Option<(Option<Operation>, RoaringBitmap)>>;
|
||||
fn next(&mut self) -> anyhow::Result<Option<CriterionResult>>;
|
||||
}
|
||||
|
||||
/// 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<Operation>,
|
||||
/// 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<RoaringBitmap>,
|
||||
}
|
||||
|
||||
/// Either a set of candidates that defines the candidates
|
||||
|
@ -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<Option<(Option<Operation>, RoaringBitmap)>> {
|
||||
fn next(&mut self) -> anyhow::Result<Option<CriterionResult>> {
|
||||
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);
|
||||
},
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user