250: Add the limit field to http-ui r=Kerollmops a=irevoire



251: Fix the limit r=Kerollmops a=irevoire

There was no check on the limit and thus if a user specified a very large number this line could cause a panic.

Co-authored-by: Tamo <tamo@meilisearch.com>
This commit is contained in:
bors[bot] 2021-06-22 13:00:52 +00:00 committed by GitHub
commit 634201244c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -687,6 +687,7 @@ async fn main() -> anyhow::Result<()> {
filters: Option<String>,
facet_filters: Option<Vec<UntaggedEither<Vec<String>, String>>>,
facet_distribution: Option<bool>,
limit: Option<usize>,
}
#[derive(Debug, Serialize)]
@ -739,6 +740,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();

View File

@ -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)?