From 3d8ca62c351ffdaa89437ca5429fe6ea2cf52e75 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 19 Jan 2023 11:25:55 +0100 Subject: [PATCH] InvalidFacetDistribution returns invalid_search_facet --- meilisearch-types/src/error.rs | 2 +- meilisearch/tests/search/errors.rs | 31 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index bf38bb14f..bc320d275 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -327,7 +327,7 @@ impl ErrorCode for milli::Error { } UserError::PrimaryKeyCannotBeChanged(_) => Code::IndexPrimaryKeyAlreadyExists, UserError::SortRankingRuleMissing => Code::InvalidSearchSort, - UserError::InvalidFacetsDistribution { .. } => Code::BadRequest, + UserError::InvalidFacetsDistribution { .. } => Code::InvalidSearchFacets, UserError::InvalidSortableAttribute { .. } => Code::InvalidSearchSort, UserError::CriterionError(_) => Code::InvalidSettingsRankingRules, UserError::InvalidGeoField { .. } => Code::InvalidDocumentGeoField, diff --git a/meilisearch/tests/search/errors.rs b/meilisearch/tests/search/errors.rs index d8a19fff1..1149d71a5 100644 --- a/meilisearch/tests/search/errors.rs +++ b/meilisearch/tests/search/errors.rs @@ -321,6 +321,37 @@ async fn search_bad_facets() { // Can't make the `attributes_to_highlight` fail with a get search since it'll accept anything as an array of strings. } +#[actix_rt::test] +async fn search_non_filterable_facets() { + let server = Server::new().await; + let index = server.index("test"); + index.update_settings(json!({"filterableAttributes": ["title"]})).await; + // Wait for the settings update to complete + index.wait_task(0).await; + + let (response, code) = index.search_post(json!({"facets": ["doggo"]})).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid facet distribution, the fields `doggo` are not set as filterable.", + "code": "invalid_search_facets", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-search-facets" + } + "###); + + let (response, code) = index.search_get("facets=doggo").await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Invalid facet distribution, the fields `doggo` are not set as filterable.", + "code": "invalid_search_facets", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-search-facets" + } + "###); +} + #[actix_rt::test] async fn search_bad_highlight_pre_tag() { let server = Server::new().await;