From 67b8678afb7f4f1bf4263e3fd1a05a4518f160ab Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 2 Feb 2023 17:03:20 +0100 Subject: [PATCH] Force exhaustive search when faceting is requested --- meilisearch/src/search.rs | 7 +++++-- milli/src/search/mod.rs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index 9e4d81ffd..1e24de3ad 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -144,6 +144,11 @@ pub fn perform_search( } let is_finite_pagination = query.is_finite_pagination(); + let has_facet_distribution = + if let Some(facets) = query.facets.as_deref() { !facets.is_empty() } else { false }; + + search.exhaustive_number_hits(is_finite_pagination || has_facet_distribution); + search.terms_matching_strategy(query.matching_strategy.into()); let max_total_hits = index @@ -151,8 +156,6 @@ pub fn perform_search( .map_err(milli::Error::from)? .unwrap_or(DEFAULT_PAGINATION_MAX_TOTAL_HITS); - search.exhaustive_number_hits(is_finite_pagination); - // compute the offset on the limit depending on the pagination mode. let (offset, limit) = if is_finite_pagination { let limit = query.hits_per_page.unwrap_or_else(DEFAULT_SEARCH_LIMIT); diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index df59634bb..9243ea181 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -112,7 +112,7 @@ impl<'a> Search<'a> { self } - /// Force the search to exhastivelly compute the number of candidates, + /// Force the search to exhaustively 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> { self.exhaustive_number_hits = exhaustive_number_hits;