mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-10-31 07:56:28 +00:00 
			
		
		
		
	Merge #5119
5119: Settings opt out error msg r=Kerollmops a=ManyTheFish # Pull Request ## Related issue PRD: https://meilisearch.notion.site/API-usage-Settings-to-opt-out-indexing-features-fff4b06b651f8108ade3f858aeb16b14?pvs=4 ## What does this PR do? Add a new error code and message when the user tries a facet search on an index where the facet search is disabled: ```json { "message": "The facet search is disabled for this index", "code": "facet_search_disabled", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#invalid_facet_search_disabled" } ``` Co-authored-by: ManyTheFish <many@meilisearch.com>
This commit is contained in:
		| @@ -279,6 +279,7 @@ InvalidSearchPage                     , InvalidRequest       , BAD_REQUEST ; | |||||||
| InvalidSearchQ                        , InvalidRequest       , BAD_REQUEST ; | InvalidSearchQ                        , InvalidRequest       , BAD_REQUEST ; | ||||||
| InvalidFacetSearchQuery               , InvalidRequest       , BAD_REQUEST ; | InvalidFacetSearchQuery               , InvalidRequest       , BAD_REQUEST ; | ||||||
| InvalidFacetSearchName                , InvalidRequest       , BAD_REQUEST ; | InvalidFacetSearchName                , InvalidRequest       , BAD_REQUEST ; | ||||||
|  | FacetSearchDisabled                   , InvalidRequest       , BAD_REQUEST ; | ||||||
| InvalidSearchVector                   , InvalidRequest       , BAD_REQUEST ; | InvalidSearchVector                   , InvalidRequest       , BAD_REQUEST ; | ||||||
| InvalidSearchShowMatchesPosition      , InvalidRequest       , BAD_REQUEST ; | InvalidSearchShowMatchesPosition      , InvalidRequest       , BAD_REQUEST ; | ||||||
| InvalidSearchShowRankingScore         , InvalidRequest       , BAD_REQUEST ; | InvalidSearchShowRankingScore         , InvalidRequest       , BAD_REQUEST ; | ||||||
|   | |||||||
| @@ -1407,6 +1407,13 @@ pub fn perform_facet_search( | |||||||
|         None => TimeBudget::default(), |         None => TimeBudget::default(), | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  |     if !index.facet_search(&rtxn)? { | ||||||
|  |         return Err(ResponseError::from_msg( | ||||||
|  |             "The facet search is disabled for this index".to_string(), | ||||||
|  |             Code::FacetSearchDisabled, | ||||||
|  |         )); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     // In the faceted search context, we want to use the intersection between the locales provided by the user |     // 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. |     // 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. |     // If the facet string is not localized, we **ignore** the locales provided by the user because the facet data has no locale. | ||||||
|   | |||||||
| @@ -221,8 +221,15 @@ async fn add_documents_and_deactivate_facet_search() { | |||||||
|     let (response, code) = |     let (response, code) = | ||||||
|         index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await; |         index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await; | ||||||
|  |  | ||||||
|     assert_eq!(code, 200, "{}", response); |     assert_eq!(code, 400, "{}", response); | ||||||
|     assert_eq!(dbg!(response)["facetHits"].as_array().unwrap().len(), 0); |     snapshot!(response, @r###" | ||||||
|  |     { | ||||||
|  |       "message": "The facet search is disabled for this index", | ||||||
|  |       "code": "facet_search_disabled", | ||||||
|  |       "type": "invalid_request", | ||||||
|  |       "link": "https://docs.meilisearch.com/errors#facet_search_disabled" | ||||||
|  |     } | ||||||
|  |     "###); | ||||||
| } | } | ||||||
|  |  | ||||||
| #[actix_rt::test] | #[actix_rt::test] | ||||||
| @@ -245,8 +252,15 @@ async fn deactivate_facet_search_and_add_documents() { | |||||||
|     let (response, code) = |     let (response, code) = | ||||||
|         index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await; |         index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await; | ||||||
|  |  | ||||||
|     assert_eq!(code, 200, "{}", response); |     assert_eq!(code, 400, "{}", response); | ||||||
|     assert_eq!(dbg!(response)["facetHits"].as_array().unwrap().len(), 0); |     snapshot!(response, @r###" | ||||||
|  |     { | ||||||
|  |       "message": "The facet search is disabled for this index", | ||||||
|  |       "code": "facet_search_disabled", | ||||||
|  |       "type": "invalid_request", | ||||||
|  |       "link": "https://docs.meilisearch.com/errors#facet_search_disabled" | ||||||
|  |     } | ||||||
|  |     "###); | ||||||
| } | } | ||||||
|  |  | ||||||
| #[actix_rt::test] | #[actix_rt::test] | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user