From 405af09fc8dd22d42af8e9b6026b75ac5ed41131 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 29 Mar 2022 11:27:53 -0700 Subject: [PATCH] Hard limit the number of results returned by a search --- meilisearch-lib/src/index/search.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/meilisearch-lib/src/index/search.rs b/meilisearch-lib/src/index/search.rs index 644b75468..757a5ec00 100644 --- a/meilisearch-lib/src/index/search.rs +++ b/meilisearch-lib/src/index/search.rs @@ -34,6 +34,10 @@ pub const fn default_crop_length() -> usize { DEFAULT_CROP_LENGTH } +/// The maximimum number of results that the engine +/// will be able to return in one search call. +pub const HARD_RESULT_LIMIT: usize = 1000; + #[derive(Deserialize, Debug, Clone, PartialEq)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct SearchQuery { @@ -124,6 +128,8 @@ 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