Extract the facet order before extracting the facets values

This commit is contained in:
Clément Renault 2024-03-12 10:35:39 +01:00
parent 82b43e9a7f
commit 69c118ef76
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F
2 changed files with 11 additions and 1 deletions

View File

@ -726,8 +726,15 @@ 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 mut facet_search =
SearchForFacetValues::new(facet_name, search, search_query.hybrid.is_some());
SearchForFacetValues::new(facet_name, search, sort_by, search_query.hybrid.is_some());
if let Some(facet_query) = &facet_query {
facet_search.query(facet_query);
}

View File

@ -307,6 +307,7 @@ pub struct SearchForFacetValues<'a> {
facet: String,
search_query: Search<'a>,
max_values: usize,
sort_by: OrderBy,
is_hybrid: bool,
}
@ -314,6 +315,7 @@ impl<'a> SearchForFacetValues<'a> {
pub fn new(
facet: String,
search_query: Search<'a>,
sort_by: OrderBy,
is_hybrid: bool,
) -> SearchForFacetValues<'a> {
SearchForFacetValues {
@ -321,6 +323,7 @@ impl<'a> SearchForFacetValues<'a> {
facet,
search_query,
max_values: DEFAULT_MAX_NUMBER_OF_VALUES_PER_FACET,
sort_by,
is_hybrid,
}
}