From f4021273b8d098f83c4b2c99100ed1228c32d24b Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Wed, 26 Oct 2022 18:08:29 +0200 Subject: [PATCH] Add is_finite_pagination method to SearchQuery --- meilisearch-http/src/analytics/segment_analytics.rs | 2 +- meilisearch-lib/src/index/search.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/meilisearch-http/src/analytics/segment_analytics.rs b/meilisearch-http/src/analytics/segment_analytics.rs index 6655a7f9b..21d41d84f 100644 --- a/meilisearch-http/src/analytics/segment_analytics.rs +++ b/meilisearch-http/src/analytics/segment_analytics.rs @@ -428,7 +428,7 @@ impl SearchAggregator { ret.max_terms_number = q.split_whitespace().count(); } - if query.hits_per_page.or(query.page).is_some() { + if query.is_finite_pagination() { let limit = query.hits_per_page.unwrap_or_else(DEFAULT_SEARCH_LIMIT); ret.max_limit = limit; ret.max_offset = query.page.unwrap_or(1).saturating_sub(1) * limit; diff --git a/meilisearch-lib/src/index/search.rs b/meilisearch-lib/src/index/search.rs index a260e52c3..558a530c0 100644 --- a/meilisearch-lib/src/index/search.rs +++ b/meilisearch-lib/src/index/search.rs @@ -63,6 +63,12 @@ pub struct SearchQuery { pub matching_strategy: MatchingStrategy, } +impl SearchQuery { + pub fn is_finite_pagination(&self) -> bool { + self.page.or(self.hits_per_page).is_some() + } +} + #[derive(Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub enum MatchingStrategy { @@ -138,14 +144,13 @@ impl Index { search.query(query); } + let is_finite_pagination = query.is_finite_pagination(); search.terms_matching_strategy(query.matching_strategy.into()); let max_total_hits = self .pagination_max_total_hits(&rtxn)? .unwrap_or(DEFAULT_PAGINATION_MAX_TOTAL_HITS); - let is_finite_pagination = query.page.or(query.hits_per_page).is_some(); - search.exhaustive_number_hits(is_finite_pagination); // compute the offset on the limit depending on the pagination mode.