diff --git a/crates/meilisearch-types/src/error.rs b/crates/meilisearch-types/src/error.rs index 4b930bf8d..c68059682 100644 --- a/crates/meilisearch-types/src/error.rs +++ b/crates/meilisearch-types/src/error.rs @@ -279,6 +279,7 @@ InvalidSearchPage , InvalidRequest , BAD_REQUEST ; InvalidSearchQ , InvalidRequest , BAD_REQUEST ; InvalidFacetSearchQuery , InvalidRequest , BAD_REQUEST ; InvalidFacetSearchName , InvalidRequest , BAD_REQUEST ; +InvalidFacetSearchDisabled , InvalidRequest , BAD_REQUEST ; InvalidSearchVector , InvalidRequest , BAD_REQUEST ; InvalidSearchShowMatchesPosition , InvalidRequest , BAD_REQUEST ; InvalidSearchShowRankingScore , InvalidRequest , BAD_REQUEST ; diff --git a/crates/meilisearch/src/search/mod.rs b/crates/meilisearch/src/search/mod.rs index 7e185e951..9e0c936b7 100644 --- a/crates/meilisearch/src/search/mod.rs +++ b/crates/meilisearch/src/search/mod.rs @@ -1407,6 +1407,13 @@ pub fn perform_facet_search( None => TimeBudget::default(), }; + if !index.facet_search(&rtxn)? { + return Err(ResponseError::from_msg( + "The facet search is disabled for this index".to_string(), + Code::InvalidFacetSearchDisabled, + )); + } + // In the faceted search context, we want to use the intersection between the locales provided by the user // and the locales of the facet string. // If the facet string is not localized, we **ignore** the locales provided by the user because the facet data has no locale. diff --git a/crates/meilisearch/tests/search/facet_search.rs b/crates/meilisearch/tests/search/facet_search.rs index 8fbeae293..418cb4da4 100644 --- a/crates/meilisearch/tests/search/facet_search.rs +++ b/crates/meilisearch/tests/search/facet_search.rs @@ -221,8 +221,15 @@ async fn add_documents_and_deactivate_facet_search() { let (response, code) = index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await; - assert_eq!(code, 200, "{}", response); - assert_eq!(dbg!(response)["facetHits"].as_array().unwrap().len(), 0); + assert_eq!(code, 400, "{}", response); + snapshot!(response, @r###" + { + "message": "Facet search is disabled for this index", + "code": "invalid_search_disabled_facet_search", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_disabled_facet_search" + } + "###); } #[actix_rt::test] @@ -245,8 +252,15 @@ async fn deactivate_facet_search_and_add_documents() { let (response, code) = index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await; - assert_eq!(code, 200, "{}", response); - assert_eq!(dbg!(response)["facetHits"].as_array().unwrap().len(), 0); + assert_eq!(code, 400, "{}", response); + snapshot!(response, @r###" + { + "message": "Facet search is disabled for this index", + "code": "invalid_search_disabled_facet_search", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_search_disabled_facet_search" + } + "###); } #[actix_rt::test]