Fix the criteria to avoid always returning a placeholder

This commit is contained in:
Kerollmops 2021-03-01 14:03:12 +01:00
parent 36c1f93ceb
commit 025835c5b2
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
5 changed files with 33 additions and 14 deletions

View File

@ -128,8 +128,11 @@ impl<'t> Criterion for AscDesc<'t> {
loop {
match (&mut self.query_tree, &mut self.candidates) {
(_, Allowed(candidates)) if candidates.is_empty() => {
self.query_tree = None;
self.candidates = Candidates::default();
return Ok(Some(CriterionResult {
query_tree: self.query_tree.take(),
candidates: take(&mut self.candidates).into_inner(),
bucket_candidates: take(&mut self.bucket_candidates),
}));
},
(Some(qt), Allowed(candidates)) => {
let bucket_candidates = match self.parent {

View File

@ -54,20 +54,26 @@ impl<'t> Criterion for Fetcher<'t> {
self.should_get_documents_ids, self.candidates,
);
let should_get_documents_ids = take(&mut self.should_get_documents_ids);
match &mut self.candidates {
Allowed(candidates) => if candidates.is_empty() {
self.candidates = Candidates::default();
} else {
self.should_get_documents_ids = false;
Allowed(candidates) => {
let candidates = take(&mut self.candidates).into_inner();
let candidates = match &self.query_tree {
Some(qt) if should_get_documents_ids => {
let mut docids = resolve_query_tree(self.ctx, &qt, &mut HashMap::new())?;
docids.intersect_with(&candidates);
docids
},
_ => candidates,
};
return Ok(Some(CriterionResult {
query_tree: self.query_tree.clone(),
query_tree: self.query_tree.take(),
candidates: candidates.clone(),
bucket_candidates: candidates,
}));
},
Forbidden(_) => {
let should_get_documents_ids = take(&mut self.should_get_documents_ids);
match self.parent.as_mut() {
Some(parent) => {
match parent.next()? {

View File

@ -64,8 +64,11 @@ impl<'t> Criterion for Proximity<'t> {
match (&mut self.query_tree, &mut self.candidates) {
(_, Allowed(candidates)) if candidates.is_empty() => {
self.query_tree = None;
self.candidates = Candidates::default();
return Ok(Some(CriterionResult {
query_tree: self.query_tree.take().map(|(_, qt)| qt),
candidates: take(&mut self.candidates).into_inner(),
bucket_candidates: take(&mut self.bucket_candidates),
}));
},
(Some((max_prox, query_tree)), Allowed(candidates)) => {
if self.proximity as usize > *max_prox {

View File

@ -64,8 +64,11 @@ impl<'t> Criterion for Typo<'t> {
match (&mut self.query_tree, &mut self.candidates) {
(_, Allowed(candidates)) if candidates.is_empty() => {
self.query_tree = None;
self.candidates = Candidates::default();
return Ok(Some(CriterionResult {
query_tree: self.query_tree.take().map(|(_, qt)| qt),
candidates: take(&mut self.candidates).into_inner(),
bucket_candidates: take(&mut self.bucket_candidates),
}));
},
(Some((max_typos, query_tree)), Allowed(candidates)) => {
if self.number_typos as usize > *max_typos {

View File

@ -56,9 +56,13 @@ impl<'t> Criterion for Words<'t> {
debug!("Words at iteration {} ({:?})", self.query_trees.len(), self.candidates);
match (self.query_trees.pop(), &mut self.candidates) {
(_, Allowed(candidates)) if candidates.is_empty() => {
(query_tree, Allowed(candidates)) if candidates.is_empty() => {
self.query_trees = Vec::new();
self.candidates = Candidates::default();
return Ok(Some(CriterionResult {
query_tree,
candidates: take(&mut self.candidates).into_inner(),
bucket_candidates: take(&mut self.bucket_candidates),
}));
},
(Some(qt), Allowed(candidates)) => {
let mut found_candidates = resolve_query_tree(self.ctx, &qt, &mut self.candidates_cache)?;