From 81643e6d70704d7675f9b50fcc41b764ecf78c15 Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 22 Jun 2021 14:47:23 +0200 Subject: [PATCH 1/2] add the limit field to http-ui --- http-ui/src/main.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/http-ui/src/main.rs b/http-ui/src/main.rs index 703861058..8035cf789 100644 --- a/http-ui/src/main.rs +++ b/http-ui/src/main.rs @@ -683,6 +683,7 @@ async fn main() -> anyhow::Result<()> { filters: Option, facet_filters: Option, String>>>, facet_distribution: Option, + limit: Option, } #[derive(Debug, Serialize)] @@ -735,6 +736,10 @@ async fn main() -> anyhow::Result<()> { search.filter(condition); } + if let Some(limit) = query.limit { + search.limit(limit); + } + let SearchResult { matching_words, candidates, documents_ids } = search.execute().unwrap(); From 3d90b03d7b0ec91db66c179dd82c3acdf487dc8e Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 22 Jun 2021 14:52:13 +0200 Subject: [PATCH 2/2] fix the limit There was no check on the limit and thus, if a user especified a very large number this line could causes a panic --- milli/src/search/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index f692df173..71d200e0c 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -162,7 +162,7 @@ impl<'a> Search<'a> { let mut offset = self.offset; let mut initial_candidates = RoaringBitmap::new(); let mut excluded_candidates = RoaringBitmap::new(); - let mut documents_ids = Vec::with_capacity(self.limit); + let mut documents_ids = Vec::new(); while let Some(FinalResult { candidates, bucket_candidates, .. }) = criteria.next(&excluded_candidates)?