From fd65cf9dcb842ebd7eb32bddf9966db838f3809e Mon Sep 17 00:00:00 2001 From: mposmta Date: Wed, 25 Mar 2020 12:44:38 +0100 Subject: [PATCH] populates exhaustive number of hits --- meilisearch-core/src/bucket_sort.rs | 12 ++++++------ meilisearch-core/src/query_builder.rs | 2 +- meilisearch-http/src/helpers/meilisearch.rs | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/meilisearch-core/src/bucket_sort.rs b/meilisearch-core/src/bucket_sort.rs index 4c34f1abd..23e7149a2 100644 --- a/meilisearch-core/src/bucket_sort.rs +++ b/meilisearch-core/src/bucket_sort.rs @@ -37,7 +37,7 @@ pub fn bucket_sort<'c, FI>( synonyms_store: store::Synonyms, prefix_documents_cache_store: store::PrefixDocumentsCache, prefix_postings_lists_cache_store: store::PrefixPostingsListsCache, -) -> MResult> +) -> MResult<(Vec, usize)> where FI: Fn(DocumentId) -> bool, { @@ -66,7 +66,7 @@ where let words_set = match unsafe { main_store.static_words_fst(reader)? } { 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(); @@ -172,7 +172,7 @@ where debug!("bucket sort took {:.02?}", before_bucket_sort.elapsed()); - Ok(documents) + Ok((documents, docids.len())) } 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, _prefix_documents_cache_store: store::PrefixDocumentsCache, prefix_postings_lists_cache_store: store::PrefixPostingsListsCache, -) -> MResult> +) -> MResult<(Vec, usize)> where FI: Fn(DocumentId) -> bool, FD: Fn(DocumentId) -> Option, { let words_set = match unsafe { main_store.static_words_fst(reader)? } { 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(); @@ -363,7 +363,7 @@ where } } - Ok(documents) + Ok((documents, docids.len())) } fn cleanup_bare_matches<'tag, 'txn>( diff --git a/meilisearch-core/src/query_builder.rs b/meilisearch-core/src/query_builder.rs index 684e3b1a8..d73f3b4dd 100644 --- a/meilisearch-core/src/query_builder.rs +++ b/meilisearch-core/src/query_builder.rs @@ -92,7 +92,7 @@ impl<'c, 'f, 'd> QueryBuilder<'c, 'f, 'd> { reader: &heed::RoTxn, query: &str, range: Range, - ) -> MResult> { + ) -> MResult<(Vec, usize)> { match self.distinct { Some((distinct, distinct_size)) => bucket_sort_with_distinct( reader, diff --git a/meilisearch-http/src/helpers/meilisearch.rs b/meilisearch-http/src/helpers/meilisearch.rs index 9aa5174ff..64140b3aa 100644 --- a/meilisearch-http/src/helpers/meilisearch.rs +++ b/meilisearch-http/src/helpers/meilisearch.rs @@ -223,12 +223,12 @@ impl<'a> SearchBuilder<'a> { } let start = Instant::now(); - let docs = - query_builder.query(reader, &self.query, self.offset..(self.offset + self.limit)); + let result = query_builder.query(reader, &self.query, self.offset..(self.offset + self.limit)); 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); - for doc in docs.map_err(|e| Error::SearchDocuments(e.to_string()))? { + for doc in docs { // retrieve the content of document in kv store let mut fields: Option> = None; if let Some(attributes_to_retrieve) = &self.attributes_to_retrieve { @@ -282,7 +282,7 @@ impl<'a> SearchBuilder<'a> { hits, offset: self.offset, limit: self.limit, - nb_hits: 0, + nb_hits, exhaustive_nb_hits: false, processing_time_ms: time_ms, query: self.query.to_string(),