populates exhaustive number of hits

This commit is contained in:
mposmta 2020-03-25 12:44:38 +01:00
parent 6e9d7f94d4
commit fd65cf9dcb
3 changed files with 11 additions and 11 deletions

View File

@ -37,7 +37,7 @@ pub fn bucket_sort<'c, FI>(
synonyms_store: store::Synonyms, synonyms_store: store::Synonyms,
prefix_documents_cache_store: store::PrefixDocumentsCache, prefix_documents_cache_store: store::PrefixDocumentsCache,
prefix_postings_lists_cache_store: store::PrefixPostingsListsCache, prefix_postings_lists_cache_store: store::PrefixPostingsListsCache,
) -> MResult<Vec<Document>> ) -> MResult<(Vec<Document>, usize)>
where where
FI: Fn(DocumentId) -> bool, FI: Fn(DocumentId) -> bool,
{ {
@ -66,7 +66,7 @@ where
let words_set = match unsafe { main_store.static_words_fst(reader)? } { let words_set = match unsafe { main_store.static_words_fst(reader)? } {
Some(words) => words, Some(words) => words,
None => return Ok(Vec::new()), None => return Ok((Vec::new(), 0)),
}; };
let stop_words = main_store.stop_words_fst(reader)?.unwrap_or_default(); let stop_words = main_store.stop_words_fst(reader)?.unwrap_or_default();
@ -172,7 +172,7 @@ where
debug!("bucket sort took {:.02?}", before_bucket_sort.elapsed()); debug!("bucket sort took {:.02?}", before_bucket_sort.elapsed());
Ok(documents) Ok((documents, docids.len()))
} }
pub fn bucket_sort_with_distinct<'c, FI, FD>( pub fn bucket_sort_with_distinct<'c, FI, FD>(
@ -190,14 +190,14 @@ pub fn bucket_sort_with_distinct<'c, FI, FD>(
synonyms_store: store::Synonyms, synonyms_store: store::Synonyms,
_prefix_documents_cache_store: store::PrefixDocumentsCache, _prefix_documents_cache_store: store::PrefixDocumentsCache,
prefix_postings_lists_cache_store: store::PrefixPostingsListsCache, prefix_postings_lists_cache_store: store::PrefixPostingsListsCache,
) -> MResult<Vec<Document>> ) -> MResult<(Vec<Document>, usize)>
where where
FI: Fn(DocumentId) -> bool, FI: Fn(DocumentId) -> bool,
FD: Fn(DocumentId) -> Option<u64>, FD: Fn(DocumentId) -> Option<u64>,
{ {
let words_set = match unsafe { main_store.static_words_fst(reader)? } { let words_set = match unsafe { main_store.static_words_fst(reader)? } {
Some(words) => words, Some(words) => words,
None => return Ok(Vec::new()), None => return Ok((Vec::new(), 0)),
}; };
let stop_words = main_store.stop_words_fst(reader)?.unwrap_or_default(); let stop_words = main_store.stop_words_fst(reader)?.unwrap_or_default();
@ -363,7 +363,7 @@ where
} }
} }
Ok(documents) Ok((documents, docids.len()))
} }
fn cleanup_bare_matches<'tag, 'txn>( fn cleanup_bare_matches<'tag, 'txn>(

View File

@ -92,7 +92,7 @@ impl<'c, 'f, 'd> QueryBuilder<'c, 'f, 'd> {
reader: &heed::RoTxn<MainT>, reader: &heed::RoTxn<MainT>,
query: &str, query: &str,
range: Range<usize>, range: Range<usize>,
) -> MResult<Vec<Document>> { ) -> MResult<(Vec<Document>, usize)> {
match self.distinct { match self.distinct {
Some((distinct, distinct_size)) => bucket_sort_with_distinct( Some((distinct, distinct_size)) => bucket_sort_with_distinct(
reader, reader,

View File

@ -223,12 +223,12 @@ impl<'a> SearchBuilder<'a> {
} }
let start = Instant::now(); let start = Instant::now();
let docs = let result = query_builder.query(reader, &self.query, self.offset..(self.offset + self.limit));
query_builder.query(reader, &self.query, self.offset..(self.offset + self.limit));
let time_ms = start.elapsed().as_millis() as usize; let time_ms = start.elapsed().as_millis() as usize;
let (docs, nb_hits) = result.map_err(|e| Error::SearchDocuments(e.to_string()))?;
let mut hits = Vec::with_capacity(self.limit); let mut hits = Vec::with_capacity(self.limit);
for doc in docs.map_err(|e| Error::SearchDocuments(e.to_string()))? { for doc in docs {
// retrieve the content of document in kv store // retrieve the content of document in kv store
let mut fields: Option<HashSet<&str>> = None; let mut fields: Option<HashSet<&str>> = None;
if let Some(attributes_to_retrieve) = &self.attributes_to_retrieve { if let Some(attributes_to_retrieve) = &self.attributes_to_retrieve {
@ -282,7 +282,7 @@ impl<'a> SearchBuilder<'a> {
hits, hits,
offset: self.offset, offset: self.offset,
limit: self.limit, limit: self.limit,
nb_hits: 0, nb_hits,
exhaustive_nb_hits: false, exhaustive_nb_hits: false,
processing_time_ms: time_ms, processing_time_ms: time_ms,
query: self.query.to_string(), query: self.query.to_string(),