Add some code comments

This commit is contained in:
ManyTheFish 2022-10-17 14:41:57 +02:00
parent cf203b7fde
commit 6f55e7844c
2 changed files with 9 additions and 2 deletions

View File

@ -5,7 +5,9 @@ use crate::search::criteria::{resolve_query_tree, Context};
use crate::search::query_tree::Operation; use crate::search::query_tree::Operation;
use crate::search::Distinct; use crate::search::Distinct;
use crate::Result; use crate::Result;
/// Initial is a mandatory criterion, it is always the first
/// and is meant to initalize the CriterionResult used by the other criteria.
/// It behave like an [Once Iterator](https://doc.rust-lang.org/std/iter/struct.Once.html) and will return Some(CriterionResult) only one time.
pub struct Initial<'t, D> { pub struct Initial<'t, D> {
ctx: &'t dyn Context<'t>, ctx: &'t dyn Context<'t>,
answer: Option<CriterionResult>, answer: Option<CriterionResult>,
@ -38,18 +40,21 @@ impl<D: Distinct> Criterion for Initial<'_, D> {
.take() .take()
.map(|mut answer| { .map(|mut answer| {
if self.exhaustive_number_hits && answer.query_tree.is_some() { if self.exhaustive_number_hits && answer.query_tree.is_some() {
// resolve the whole query tree to retrieve an exhastive list of documents matching the query.
let mut candidates = resolve_query_tree( let mut candidates = resolve_query_tree(
self.ctx, self.ctx,
answer.query_tree.as_ref().unwrap(), answer.query_tree.as_ref().unwrap(),
&mut params.wdcache, &mut params.wdcache,
)?; )?;
// Apply the filters on the documents retrieved with the query tree.
if let Some(ref filtered_candidates) = answer.filtered_candidates { if let Some(ref filtered_candidates) = answer.filtered_candidates {
candidates &= filtered_candidates; candidates &= filtered_candidates;
} }
// because the bucket_candidates should be an exhastive count of the matching documents,
// we precompute the distinct attributes.
let bucket_candidates = match &mut self.distinct { let bucket_candidates = match &mut self.distinct {
// may be really time consuming
Some(distinct) => { Some(distinct) => {
let mut bucket_candidates = RoaringBitmap::new(); let mut bucket_candidates = RoaringBitmap::new();
for c in distinct.distinct(candidates.clone(), RoaringBitmap::new()) { for c in distinct.distinct(candidates.clone(), RoaringBitmap::new()) {

View File

@ -109,6 +109,8 @@ impl<'a> Search<'a> {
self self
} }
/// Force the search to exhastivelly compute the number of candidates,
/// this will increase the search time but allows finite pagination.
pub fn exhaustive_number_hits(&mut self, exhaustive_number_hits: bool) -> &mut Search<'a> { pub fn exhaustive_number_hits(&mut self, exhaustive_number_hits: bool) -> &mut Search<'a> {
self.exhaustive_number_hits = exhaustive_number_hits; self.exhaustive_number_hits = exhaustive_number_hits;
self self