mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-12-05 12:15:42 +00:00
Restrict the number of facet search results to 1000
This commit is contained in:
@@ -33,6 +33,9 @@ static LEVDIST0: Lazy<LevBuilder> = Lazy::new(|| LevBuilder::new(0, true));
|
||||
static LEVDIST1: Lazy<LevBuilder> = Lazy::new(|| LevBuilder::new(1, true));
|
||||
static LEVDIST2: Lazy<LevBuilder> = Lazy::new(|| LevBuilder::new(2, true));
|
||||
|
||||
/// The maximum number of facets returned by the facet search route.
|
||||
const MAX_NUMBER_OF_FACETS: usize = 1000;
|
||||
|
||||
mod criteria;
|
||||
mod distinct;
|
||||
pub mod facet;
|
||||
@@ -501,6 +504,7 @@ impl<'a> SearchForFacetValue<'a> {
|
||||
|
||||
let mut stream = fst.search(automaton).into_stream();
|
||||
let mut result = vec![];
|
||||
let mut length = 0;
|
||||
while let Some(facet_value) = stream.next() {
|
||||
let value = std::str::from_utf8(facet_value)?;
|
||||
let key = FacetGroupKey { field_id, level: 0, left_bound: value };
|
||||
@@ -511,6 +515,10 @@ impl<'a> SearchForFacetValue<'a> {
|
||||
let count = search_candidates.intersection_len(&docids);
|
||||
if count != 0 {
|
||||
result.push(FacetSearchResult { value: value.to_string(), count });
|
||||
length += 1;
|
||||
}
|
||||
if length >= MAX_NUMBER_OF_FACETS {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,6 +527,7 @@ impl<'a> SearchForFacetValue<'a> {
|
||||
None => {
|
||||
let mut stream = fst.stream();
|
||||
let mut result = vec![];
|
||||
let mut length = 0;
|
||||
while let Some(facet_value) = stream.next() {
|
||||
let value = std::str::from_utf8(facet_value)?;
|
||||
let key = FacetGroupKey { field_id, level: 0, left_bound: value };
|
||||
@@ -529,6 +538,10 @@ impl<'a> SearchForFacetValue<'a> {
|
||||
let count = search_candidates.intersection_len(&docids);
|
||||
if count != 0 {
|
||||
result.push(FacetSearchResult { value: value.to_string(), count });
|
||||
length += 1;
|
||||
}
|
||||
if length >= MAX_NUMBER_OF_FACETS {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user