mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-03-06 22:02:34 +08:00
Add an exhaustiveFacetCount field to the facet-search API
This commit is contained in:
parent
5e7803632d
commit
c7333a06c5
@ -281,6 +281,7 @@ InvalidSearchCropMarker , InvalidRequest , BAD_REQUEST ;
|
|||||||
InvalidSearchFacets , InvalidRequest , BAD_REQUEST ;
|
InvalidSearchFacets , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSearchSemanticRatio , InvalidRequest , BAD_REQUEST ;
|
InvalidSearchSemanticRatio , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSearchLocales , InvalidRequest , BAD_REQUEST ;
|
InvalidSearchLocales , InvalidRequest , BAD_REQUEST ;
|
||||||
|
InvalidFacetSearchExhaustiveFacetCount, InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidFacetSearchFacetName , InvalidRequest , BAD_REQUEST ;
|
InvalidFacetSearchFacetName , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSimilarId , InvalidRequest , BAD_REQUEST ;
|
InvalidSimilarId , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSearchFilter , InvalidRequest , BAD_REQUEST ;
|
InvalidSearchFilter , InvalidRequest , BAD_REQUEST ;
|
||||||
|
@ -68,6 +68,8 @@ pub struct FacetSearchQuery {
|
|||||||
pub ranking_score_threshold: Option<RankingScoreThreshold>,
|
pub ranking_score_threshold: Option<RankingScoreThreshold>,
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidSearchLocales>, default)]
|
#[deserr(default, error = DeserrJsonError<InvalidSearchLocales>, default)]
|
||||||
pub locales: Option<Vec<Locale>>,
|
pub locales: Option<Vec<Locale>>,
|
||||||
|
#[deserr(default, error = DeserrJsonError<InvalidFacetSearchExhaustiveFacetCount>, default)]
|
||||||
|
pub exhaustive_facet_count: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -98,6 +100,7 @@ impl FacetSearchAggregator {
|
|||||||
hybrid,
|
hybrid,
|
||||||
ranking_score_threshold,
|
ranking_score_threshold,
|
||||||
locales,
|
locales,
|
||||||
|
exhaustive_facet_count,
|
||||||
} = query;
|
} = query;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@ -110,7 +113,8 @@ impl FacetSearchAggregator {
|
|||||||
|| attributes_to_search_on.is_some()
|
|| attributes_to_search_on.is_some()
|
||||||
|| hybrid.is_some()
|
|| hybrid.is_some()
|
||||||
|| ranking_score_threshold.is_some()
|
|| ranking_score_threshold.is_some()
|
||||||
|| locales.is_some(),
|
|| locales.is_some()
|
||||||
|
|| exhaustive_facet_count.is_some(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,13 +297,24 @@ impl From<FacetSearchQuery> for SearchQuery {
|
|||||||
hybrid,
|
hybrid,
|
||||||
ranking_score_threshold,
|
ranking_score_threshold,
|
||||||
locales,
|
locales,
|
||||||
|
exhaustive_facet_count,
|
||||||
} = value;
|
} = value;
|
||||||
|
|
||||||
|
// If exhaustive_facet_count is true, we need to set the page to 0
|
||||||
|
// because the facet search is not exhaustive by default.
|
||||||
|
let page = if exhaustive_facet_count.map_or(false, |exhaustive| exhaustive) {
|
||||||
|
// setting the page to 0 will force the search to be exhaustive when computing the number of hits,
|
||||||
|
// but it will skip the bucket sort saving time.
|
||||||
|
Some(0)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
SearchQuery {
|
SearchQuery {
|
||||||
q,
|
q,
|
||||||
offset: DEFAULT_SEARCH_OFFSET(),
|
offset: DEFAULT_SEARCH_OFFSET(),
|
||||||
limit: DEFAULT_SEARCH_LIMIT(),
|
limit: DEFAULT_SEARCH_LIMIT(),
|
||||||
page: None,
|
page,
|
||||||
hits_per_page: None,
|
hits_per_page: None,
|
||||||
attributes_to_retrieve: None,
|
attributes_to_retrieve: None,
|
||||||
retrieve_vectors: false,
|
retrieve_vectors: false,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user