From dc8a662209395378dc9a6c17e3f1def3f00a218c Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Tue, 17 Sep 2024 10:08:21 +0200 Subject: [PATCH] federated queries: adjust error message --- meilisearch/src/error.rs | 8 ++++---- meilisearch/src/search/federated.rs | 10 ++++++++-- meilisearch/src/search/mod.rs | 5 ++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/meilisearch/src/error.rs b/meilisearch/src/error.rs index fa315837f..9d5eff016 100644 --- a/meilisearch/src/error.rs +++ b/meilisearch/src/error.rs @@ -32,9 +32,9 @@ pub enum MeilisearchHttpError { FederationOptionsInNonFederatedRequest(usize), #[error("Inside `.queries[{0}]`: Using pagination options is not allowed in federated queries.\n - Hint: remove `{1}` from query #{0} or remove `federation` from the request\n - Hint: pass `federation.limit` and `federation.offset` for pagination in federated search")] PaginationInFederatedQuery(usize, &'static str), - #[error("Inside `.queries[{0}]`: Using facet options is not allowed in federated queries.\n Hint: remove `facets` from query #{0} or remove `federation` from the request")] - FacetsInFederatedQuery(usize), - #[error("Inconsistent order for values in facet `{facet}`: index `{previous_uid}` orders {previous_facet_order}, but index `{current_uid}` orders {index_facet_order}.\n Hint: Remove `federation.mergeFacets` or set `federation.mergeFacets.sortFacetValuesBy` to the desired order.")] + #[error("Inside `.queries[{0}]`: Using facet options is not allowed in federated queries.\n - Hint: remove `facets` from query #{0} or remove `federation` from the request\n - Hint: pass `federation.facetsByIndex.{1}: {2:?}` for facets in federated search")] + FacetsInFederatedQuery(usize, String, Vec), + #[error("Inconsistent order for values in facet `{facet}`: index `{previous_uid}` orders {previous_facet_order}, but index `{current_uid}` orders {index_facet_order}.\n - Hint: Remove `federation.mergeFacets` or set `federation.mergeFacets.sortFacetValuesBy` to the desired order.")] InconsistentFacetOrder { facet: String, previous_facet_order: OrderBy, @@ -107,7 +107,7 @@ impl ErrorCode for MeilisearchHttpError { MeilisearchHttpError::PaginationInFederatedQuery(_, _) => { Code::InvalidMultiSearchQueryPagination } - MeilisearchHttpError::FacetsInFederatedQuery(_) => Code::InvalidMultiSearchQueryFacets, + MeilisearchHttpError::FacetsInFederatedQuery(..) => Code::InvalidMultiSearchQueryFacets, MeilisearchHttpError::InconsistentFacetOrder { .. } => { Code::InvalidMultiSearchFacetOrder } diff --git a/meilisearch/src/search/federated.rs b/meilisearch/src/search/federated.rs index 6470002ab..46643556d 100644 --- a/meilisearch/src/search/federated.rs +++ b/meilisearch/src/search/federated.rs @@ -513,8 +513,14 @@ pub fn perform_federated_search( .into()); } - if federated_query.has_facets() { - return Err(MeilisearchHttpError::FacetsInFederatedQuery(query_index).into()); + if let Some(facets) = federated_query.has_facets() { + let facets = facets.to_owned(); + return Err(MeilisearchHttpError::FacetsInFederatedQuery( + query_index, + federated_query.index_uid.into_inner(), + facets, + ) + .into()); } let (index_uid, query, federation_options) = federated_query.into_index_query_federation(); diff --git a/meilisearch/src/search/mod.rs b/meilisearch/src/search/mod.rs index 13cfb9334..4d5d8d890 100644 --- a/meilisearch/src/search/mod.rs +++ b/meilisearch/src/search/mod.rs @@ -455,9 +455,8 @@ impl SearchQueryWithIndex { } } - pub fn has_facets(&self) -> bool { - let Some(facets) = &self.facets else { return false }; - !facets.is_empty() + pub fn has_facets(&self) -> Option<&[String]> { + self.facets.as_deref().filter(|v| !v.is_empty()) } pub fn into_index_query_federation(self) -> (IndexUid, SearchQuery, Option) {