mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 20:07:09 +02:00
Introduce a new OrderByMap struct to simplify the sort by usage
This commit is contained in:
parent
69c118ef76
commit
d3a95ea2f6
5 changed files with 73 additions and 33 deletions
|
@ -671,27 +671,16 @@ pub fn perform_search(
|
|||
|
||||
let sort_facet_values_by =
|
||||
index.sort_facet_values_by(&rtxn).map_err(milli::Error::from)?;
|
||||
let default_sort_facet_values_by =
|
||||
sort_facet_values_by.get("*").copied().unwrap_or_default();
|
||||
|
||||
if fields.iter().all(|f| f != "*") {
|
||||
let fields: Vec<_> = fields
|
||||
.iter()
|
||||
.map(|n| {
|
||||
(
|
||||
n,
|
||||
sort_facet_values_by
|
||||
.get(n)
|
||||
.copied()
|
||||
.unwrap_or(default_sort_facet_values_by),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let fields: Vec<_> =
|
||||
fields.iter().map(|n| (n, sort_facet_values_by.get(n))).collect();
|
||||
facet_distribution.facets(fields);
|
||||
}
|
||||
|
||||
let distribution = facet_distribution
|
||||
.candidates(candidates)
|
||||
.default_order_by(default_sort_facet_values_by)
|
||||
.default_order_by(sort_facet_values_by.get("*"))
|
||||
.execute()?;
|
||||
let stats = facet_distribution.compute_stats()?;
|
||||
(Some(distribution), Some(stats))
|
||||
|
@ -726,13 +715,7 @@ pub fn perform_facet_search(
|
|||
let rtxn = index.read_txn()?;
|
||||
|
||||
let (search, _, _, _) = prepare_search(index, &rtxn, &search_query, features, None)?;
|
||||
let sort_by = {
|
||||
let sorts = index.sort_facet_values_by(&rtxn)?;
|
||||
sorts
|
||||
.get(&facet_name)
|
||||
.copied()
|
||||
.unwrap_or_else(|| sorts.get("*").copied().unwrap_or_default())
|
||||
};
|
||||
let sort_by = index.sort_facet_values_by(&rtxn)?.get(&facet_name);
|
||||
let mut facet_search =
|
||||
SearchForFacetValues::new(facet_name, search, sort_by, search_query.hybrid.is_some());
|
||||
if let Some(facet_query) = &facet_query {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue