From 8bc6e8dcf90d40bb7744acd2479634389c3b3019 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 30 Mar 2022 10:06:15 -0700 Subject: [PATCH] Make sure that offsets are clamped too --- meilisearch-lib/src/index/search.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/meilisearch-lib/src/index/search.rs b/meilisearch-lib/src/index/search.rs index 757a5ec00..1498b70bd 100644 --- a/meilisearch-lib/src/index/search.rs +++ b/meilisearch-lib/src/index/search.rs @@ -1,3 +1,4 @@ +use std::cmp::min; use std::collections::{BTreeMap, BTreeSet, HashSet}; use std::str::FromStr; use std::time::Instant; @@ -101,8 +102,13 @@ impl Index { search.query(query); } - search.limit(query.limit); - search.offset(query.offset.unwrap_or_default()); + // Make sure that a user can't get more documents than the hard limit, + // we align that on the offset too. + let offset = min(query.offset.unwrap_or(0), HARD_RESULT_LIMIT); + let limit = min(query.limit, HARD_RESULT_LIMIT.saturating_sub(offset)); + + search.offset(offset); + search.limit(limit); if let Some(ref filter) = query.filter { if let Some(facets) = parse_filter(filter)? { @@ -128,8 +134,6 @@ impl Index { .. } = search.execute()?; - let documents_ids: Vec<_> = documents_ids.into_iter().take(HARD_RESULT_LIMIT).collect(); - let fields_ids_map = self.fields_ids_map(&rtxn).unwrap(); let displayed_ids = self