Add settings to force milli to exhaustively compute the total number of hits

This commit is contained in:
ManyTheFish
2022-07-12 17:56:50 +02:00
parent fad0de4581
commit a396806343
5 changed files with 45 additions and 12 deletions

View File

@ -47,6 +47,7 @@ pub struct Search<'a> {
terms_matching_strategy: TermsMatchingStrategy,
authorize_typos: bool,
words_limit: usize,
exhaustive_number_hits: bool,
rtxn: &'a heed::RoTxn<'a>,
index: &'a Index,
}
@ -61,6 +62,7 @@ impl<'a> Search<'a> {
sort_criteria: None,
terms_matching_strategy: TermsMatchingStrategy::default(),
authorize_typos: true,
exhaustive_number_hits: false,
words_limit: 10,
rtxn,
index,
@ -107,6 +109,11 @@ impl<'a> Search<'a> {
self
}
pub fn exhaustive_number_hits(&mut self, exhaustive_number_hits: bool) -> &mut Search<'a> {
self.exhaustive_number_hits = exhaustive_number_hits;
self
}
fn is_typo_authorized(&self) -> Result<bool> {
let index_authorizes_typos = self.index.authorize_typos(self.rtxn)?;
// only authorize typos if both the index and the query allow it.
@ -189,6 +196,7 @@ impl<'a> Search<'a> {
primitive_query,
filtered_candidates,
self.sort_criteria.clone(),
self.exhaustive_number_hits,
)?;
match self.index.distinct_field(self.rtxn)? {
@ -262,6 +270,7 @@ impl fmt::Debug for Search<'_> {
terms_matching_strategy,
authorize_typos,
words_limit,
exhaustive_number_hits,
rtxn: _,
index: _,
} = self;
@ -273,6 +282,7 @@ impl fmt::Debug for Search<'_> {
.field("sort_criteria", sort_criteria)
.field("terms_matching_strategy", terms_matching_strategy)
.field("authorize_typos", authorize_typos)
.field("exhaustive_number_hits", exhaustive_number_hits)
.field("words_limit", words_limit)
.finish()
}