From 69c118ef766f19745ba8800c508e3a1cf686288b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Tue, 12 Mar 2024 10:35:39 +0100 Subject: [PATCH] Extract the facet order before extracting the facets values --- meilisearch/src/search.rs | 9 ++++++++- milli/src/search/mod.rs | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index 27de36c6d..6e253baad 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -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); } diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index e411bd032..2b0dbe423 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -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, } }