Make sure that offsets are clamped too

This commit is contained in:
Kerollmops 2022-03-30 10:06:15 -07:00
parent 405af09fc8
commit 8bc6e8dcf9
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

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