Remove excluded document in criteria iterations

- pass excluded document to criteria to remove them in higher levels of the bucket-sort
- merge already returned document with excluded documents to avoid duplicas

Related to #125 and #112
Fix #170
This commit is contained in:
many
2021-04-28 18:01:23 +02:00
parent 374c2782ad
commit ee09e50e7f
9 changed files with 149 additions and 62 deletions

View File

@ -165,13 +165,13 @@ impl<'a> Search<'a> {
) -> anyhow::Result<SearchResult> {
let mut offset = self.offset;
let mut initial_candidates = RoaringBitmap::new();
let mut excluded_documents = RoaringBitmap::new();
let mut excluded_candidates = RoaringBitmap::new();
let mut documents_ids = Vec::with_capacity(self.limit);
while let Some(FinalResult { candidates, bucket_candidates, .. }) = criteria.next()? {
while let Some(FinalResult { candidates, bucket_candidates, .. }) = criteria.next(&excluded_candidates)? {
debug!("Number of candidates found {}", candidates.len());
let excluded = take(&mut excluded_documents);
let excluded = take(&mut excluded_candidates);
let mut candidates = distinct.distinct(candidates, excluded);
@ -186,7 +186,7 @@ impl<'a> Search<'a> {
documents_ids.push(candidate?);
}
if documents_ids.len() == self.limit { break }
excluded_documents = candidates.into_excluded();
excluded_candidates = candidates.into_excluded();
}
Ok(SearchResult { matching_words, candidates: initial_candidates, documents_ids })