mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 03:55:07 +08:00
compute_facets accepts Route argument to fixup error code
This commit is contained in:
parent
91dfab317f
commit
38c4be1c8e
@ -991,7 +991,15 @@ pub fn perform_search(
|
|||||||
|
|
||||||
let (facet_distribution, facet_stats) = facets
|
let (facet_distribution, facet_stats) = facets
|
||||||
.map(move |facets| {
|
.map(move |facets| {
|
||||||
compute_facet_distribution_stats(&facets, index, &rtxn, candidates, None, None)
|
compute_facet_distribution_stats(
|
||||||
|
&facets,
|
||||||
|
index,
|
||||||
|
&rtxn,
|
||||||
|
candidates,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Route::Search,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.map(|ComputedFacets { distribution, stats }| (distribution, stats))
|
.map(|ComputedFacets { distribution, stats }| (distribution, stats))
|
||||||
@ -1017,6 +1025,11 @@ pub struct ComputedFacets {
|
|||||||
pub stats: BTreeMap<String, FacetStats>,
|
pub stats: BTreeMap<String, FacetStats>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Route {
|
||||||
|
Search,
|
||||||
|
MultiSearch,
|
||||||
|
}
|
||||||
|
|
||||||
fn compute_facet_distribution_stats<S: AsRef<str>>(
|
fn compute_facet_distribution_stats<S: AsRef<str>>(
|
||||||
facets: &[S],
|
facets: &[S],
|
||||||
index: &Index,
|
index: &Index,
|
||||||
@ -1024,6 +1037,7 @@ fn compute_facet_distribution_stats<S: AsRef<str>>(
|
|||||||
candidates: roaring::RoaringBitmap,
|
candidates: roaring::RoaringBitmap,
|
||||||
override_max_values_per_facet: Option<usize>,
|
override_max_values_per_facet: Option<usize>,
|
||||||
override_sort_facet_values_by: Option<OrderBy>,
|
override_sort_facet_values_by: Option<OrderBy>,
|
||||||
|
route: Route,
|
||||||
) -> Result<ComputedFacets, ResponseError> {
|
) -> Result<ComputedFacets, ResponseError> {
|
||||||
let mut facet_distribution = index.facets_distribution(rtxn);
|
let mut facet_distribution = index.facets_distribution(rtxn);
|
||||||
|
|
||||||
@ -1054,7 +1068,16 @@ fn compute_facet_distribution_stats<S: AsRef<str>>(
|
|||||||
let distribution = facet_distribution
|
let distribution = facet_distribution
|
||||||
.candidates(candidates)
|
.candidates(candidates)
|
||||||
.default_order_by(sort_facet_values_by("*"))
|
.default_order_by(sort_facet_values_by("*"))
|
||||||
.execute()?;
|
.execute()
|
||||||
|
.map_err(|error| match (error, route) {
|
||||||
|
(
|
||||||
|
error @ milli::Error::UserError(milli::UserError::InvalidFacetsDistribution {
|
||||||
|
..
|
||||||
|
}),
|
||||||
|
Route::MultiSearch,
|
||||||
|
) => ResponseError::from_msg(error.to_string(), Code::InvalidMultiSearchFacets),
|
||||||
|
(error, _) => error.into(),
|
||||||
|
})?;
|
||||||
let stats = facet_distribution.compute_stats()?;
|
let stats = facet_distribution.compute_stats()?;
|
||||||
let stats = stats.into_iter().map(|(k, (min, max))| (k, FacetStats { min, max })).collect();
|
let stats = stats.into_iter().map(|(k, (min, max))| (k, FacetStats { min, max })).collect();
|
||||||
Ok(ComputedFacets { distribution, stats })
|
Ok(ComputedFacets { distribution, stats })
|
||||||
|
Loading…
Reference in New Issue
Block a user