From 114f878205769c216690bd88ef7e78ddb4d516ca Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Tue, 20 Jun 2023 10:00:35 +0200 Subject: [PATCH] Rename restrictSearchableAttributes into attributesToSearchOn --- meilisearch-types/src/error.rs | 2 +- meilisearch/src/routes/indexes/search.rs | 8 ++-- meilisearch/src/search.rs | 14 +++---- .../tests/search/restrict_searchable.rs | 38 ++++++++----------- 4 files changed, 27 insertions(+), 35 deletions(-) diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index cb6f78c94..8ce7102cb 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -224,7 +224,7 @@ InvalidIndexLimit , InvalidRequest , BAD_REQUEST ; InvalidIndexOffset , InvalidRequest , BAD_REQUEST ; InvalidIndexPrimaryKey , InvalidRequest , BAD_REQUEST ; InvalidIndexUid , InvalidRequest , BAD_REQUEST ; -InvalidRestrictSearchableAttributes , InvalidRequest , BAD_REQUEST ; +InvalidAttributesToSearchOn , InvalidRequest , BAD_REQUEST ; InvalidSearchAttributesToCrop , InvalidRequest , BAD_REQUEST ; InvalidSearchAttributesToHighlight , InvalidRequest , BAD_REQUEST ; InvalidSearchAttributesToRetrieve , InvalidRequest , BAD_REQUEST ; diff --git a/meilisearch/src/routes/indexes/search.rs b/meilisearch/src/routes/indexes/search.rs index db0aedda5..06daa1e5a 100644 --- a/meilisearch/src/routes/indexes/search.rs +++ b/meilisearch/src/routes/indexes/search.rs @@ -70,8 +70,8 @@ pub struct SearchQueryGet { crop_marker: String, #[deserr(default, error = DeserrQueryParamError)] matching_strategy: MatchingStrategy, - #[deserr(default, error = DeserrQueryParamError)] - pub restrict_searchable_attributes: Option>, + #[deserr(default, error = DeserrQueryParamError)] + pub attributes_to_search_on: Option>, } impl From for SearchQuery { @@ -104,9 +104,7 @@ impl From for SearchQuery { highlight_post_tag: other.highlight_post_tag, crop_marker: other.crop_marker, matching_strategy: other.matching_strategy, - restrict_searchable_attributes: other - .restrict_searchable_attributes - .map(|o| o.into_iter().collect()), + attributes_to_search_on: other.attributes_to_search_on.map(|o| o.into_iter().collect()), } } } diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index 3a91ea655..ce96ec748 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -73,8 +73,8 @@ pub struct SearchQuery { pub crop_marker: String, #[deserr(default, error = DeserrJsonError, default)] pub matching_strategy: MatchingStrategy, - #[deserr(default, error = DeserrJsonError, default)] - pub restrict_searchable_attributes: Option>, + #[deserr(default, error = DeserrJsonError, default)] + pub attributes_to_search_on: Option>, } impl SearchQuery { @@ -130,8 +130,8 @@ pub struct SearchQueryWithIndex { pub crop_marker: String, #[deserr(default, error = DeserrJsonError, default)] pub matching_strategy: MatchingStrategy, - #[deserr(default, error = DeserrJsonError, default)] - pub restrict_searchable_attributes: Option>, + #[deserr(default, error = DeserrJsonError, default)] + pub attributes_to_search_on: Option>, } impl SearchQueryWithIndex { @@ -157,7 +157,7 @@ impl SearchQueryWithIndex { highlight_post_tag, crop_marker, matching_strategy, - restrict_searchable_attributes, + attributes_to_search_on, } = self; ( index_uid, @@ -181,7 +181,7 @@ impl SearchQueryWithIndex { highlight_post_tag, crop_marker, matching_strategy, - restrict_searchable_attributes, + attributes_to_search_on, // do not use ..Default::default() here, // rather add any missing field from `SearchQuery` to `SearchQueryWithIndex` }, @@ -297,7 +297,7 @@ pub fn perform_search( search.query(query); } - if let Some(ref searchable) = query.restrict_searchable_attributes { + if let Some(ref searchable) = query.attributes_to_search_on { search.searchable_attributes(searchable); } diff --git a/meilisearch/tests/search/restrict_searchable.rs b/meilisearch/tests/search/restrict_searchable.rs index 7c3b1a546..79f7f9733 100644 --- a/meilisearch/tests/search/restrict_searchable.rs +++ b/meilisearch/tests/search/restrict_searchable.rs @@ -39,7 +39,7 @@ async fn simple_search_on_title() { // simple search should return 2 documents (ids: 2 and 3). index .search( - json!({"q": "Captain Marvel", "restrictSearchableAttributes": ["title"]}), + json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"]}), |response, code| { assert_eq!(code, 200, "{}", response); assert_eq!(response["hits"].as_array().unwrap().len(), 2); @@ -55,13 +55,10 @@ async fn simple_prefix_search_on_title() { // simple search should return 2 documents (ids: 2 and 3). index - .search( - json!({"q": "Captain Mar", "restrictSearchableAttributes": ["title"]}), - |response, code| { - assert_eq!(code, 200, "{}", response); - assert_eq!(response["hits"].as_array().unwrap().len(), 2); - }, - ) + .search(json!({"q": "Captain Mar", "attributesToSearchOn": ["title"]}), |response, code| { + assert_eq!(code, 200, "{}", response); + assert_eq!(response["hits"].as_array().unwrap().len(), 2); + }) .await; } @@ -71,7 +68,7 @@ async fn simple_search_on_title_matching_strategy_all() { let index = index_with_documents(&server, &SIMPLE_SEARCH_DOCUMENTS).await; // simple search matching strategy all should only return 1 document (ids: 2). index - .search(json!({"q": "Captain Marvel", "restrictSearchableAttributes": ["title"], "matchingStrategy": "all"}), |response, code| { + .search(json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "matchingStrategy": "all"}), |response, code| { assert_eq!(code, 200, "{}", response); assert_eq!(response["hits"].as_array().unwrap().len(), 1); }) @@ -85,7 +82,7 @@ async fn simple_search_on_unknown_field() { // simple search on unknown field shouldn't return any document. index .search( - json!({"q": "Captain Marvel", "restrictSearchableAttributes": ["unknown"]}), + json!({"q": "Captain Marvel", "attributesToSearchOn": ["unknown"]}), |response, code| { assert_eq!(code, 200, "{}", response); assert_eq!(response["hits"].as_array().unwrap().len(), 0); @@ -100,13 +97,10 @@ async fn simple_search_on_no_field() { let index = index_with_documents(&server, &SIMPLE_SEARCH_DOCUMENTS).await; // simple search on no field shouldn't return any document. index - .search( - json!({"q": "Captain Marvel", "restrictSearchableAttributes": []}), - |response, code| { - assert_eq!(code, 200, "{}", response); - assert_eq!(response["hits"].as_array().unwrap().len(), 0); - }, - ) + .search(json!({"q": "Captain Marvel", "attributesToSearchOn": []}), |response, code| { + assert_eq!(code, 200, "{}", response); + assert_eq!(response["hits"].as_array().unwrap().len(), 0); + }) .await; } @@ -118,7 +112,7 @@ async fn word_ranking_rule_order() { // Document 3 should appear before document 2. index .search( - json!({"q": "Captain Marvel", "restrictSearchableAttributes": ["title"], "attributesToRetrieve": ["id"]}), + json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "attributesToRetrieve": ["id"]}), |response, code| { assert_eq!(code, 200, "{}", response); assert_eq!( @@ -143,7 +137,7 @@ async fn word_ranking_rule_order_exact_words() { // simple search should return 2 documents (ids: 2 and 3). index .search( - json!({"q": "Captain Marvel", "restrictSearchableAttributes": ["title"], "attributesToRetrieve": ["id"]}), + json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "attributesToRetrieve": ["id"]}), |response, code| { assert_eq!(code, 200, "{}", response); assert_eq!( @@ -179,7 +173,7 @@ async fn typo_ranking_rule_order() { // Document 2 should appear before document 1. index - .search(json!({"q": "Captain Marvel", "restrictSearchableAttributes": ["title"], "attributesToRetrieve": ["id"]}), |response, code| { + .search(json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "attributesToRetrieve": ["id"]}), |response, code| { assert_eq!(code, 200, "{}", response); assert_eq!( response["hits"], @@ -215,7 +209,7 @@ async fn attributes_ranking_rule_order() { // Document 2 should appear before document 1. index - .search(json!({"q": "Captain Marvel", "restrictSearchableAttributes": ["desc", "footer"], "attributesToRetrieve": ["id"]}), |response, code| { + .search(json!({"q": "Captain Marvel", "attributesToSearchOn": ["desc", "footer"], "attributesToRetrieve": ["id"]}), |response, code| { assert_eq!(code, 200, "{}", response); assert_eq!( response["hits"], @@ -249,7 +243,7 @@ async fn exactness_ranking_rule_order() { // Document 2 should appear before document 1. index - .search(json!({"q": "Captain Marvel", "attributesToRetrieve": ["id"], "restrictSearchableAttributes": ["desc"]}), |response, code| { + .search(json!({"q": "Captain Marvel", "attributesToRetrieve": ["id"], "attributesToSearchOn": ["desc"]}), |response, code| { assert_eq!(code, 200, "{}", response); assert_eq!( response["hits"],