Rename restrictSearchableAttributes into attributesToSearchOn

This commit is contained in:
ManyTheFish 2023-06-20 10:00:35 +02:00
parent 42709ea9a5
commit 114f878205
4 changed files with 27 additions and 35 deletions

View File

@ -224,7 +224,7 @@ InvalidIndexLimit , InvalidRequest , BAD_REQUEST ;
InvalidIndexOffset , InvalidRequest , BAD_REQUEST ; InvalidIndexOffset , InvalidRequest , BAD_REQUEST ;
InvalidIndexPrimaryKey , InvalidRequest , BAD_REQUEST ; InvalidIndexPrimaryKey , InvalidRequest , BAD_REQUEST ;
InvalidIndexUid , InvalidRequest , BAD_REQUEST ; InvalidIndexUid , InvalidRequest , BAD_REQUEST ;
InvalidRestrictSearchableAttributes , InvalidRequest , BAD_REQUEST ; InvalidAttributesToSearchOn , InvalidRequest , BAD_REQUEST ;
InvalidSearchAttributesToCrop , InvalidRequest , BAD_REQUEST ; InvalidSearchAttributesToCrop , InvalidRequest , BAD_REQUEST ;
InvalidSearchAttributesToHighlight , InvalidRequest , BAD_REQUEST ; InvalidSearchAttributesToHighlight , InvalidRequest , BAD_REQUEST ;
InvalidSearchAttributesToRetrieve , InvalidRequest , BAD_REQUEST ; InvalidSearchAttributesToRetrieve , InvalidRequest , BAD_REQUEST ;

View File

@ -70,8 +70,8 @@ pub struct SearchQueryGet {
crop_marker: String, crop_marker: String,
#[deserr(default, error = DeserrQueryParamError<InvalidSearchMatchingStrategy>)] #[deserr(default, error = DeserrQueryParamError<InvalidSearchMatchingStrategy>)]
matching_strategy: MatchingStrategy, matching_strategy: MatchingStrategy,
#[deserr(default, error = DeserrQueryParamError<InvalidRestrictSearchableAttributes>)] #[deserr(default, error = DeserrQueryParamError<InvalidAttributesToSearchOn>)]
pub restrict_searchable_attributes: Option<CS<String>>, pub attributes_to_search_on: Option<CS<String>>,
} }
impl From<SearchQueryGet> for SearchQuery { impl From<SearchQueryGet> for SearchQuery {
@ -104,9 +104,7 @@ impl From<SearchQueryGet> for SearchQuery {
highlight_post_tag: other.highlight_post_tag, highlight_post_tag: other.highlight_post_tag,
crop_marker: other.crop_marker, crop_marker: other.crop_marker,
matching_strategy: other.matching_strategy, matching_strategy: other.matching_strategy,
restrict_searchable_attributes: other attributes_to_search_on: other.attributes_to_search_on.map(|o| o.into_iter().collect()),
.restrict_searchable_attributes
.map(|o| o.into_iter().collect()),
} }
} }
} }

View File

@ -73,8 +73,8 @@ pub struct SearchQuery {
pub crop_marker: String, pub crop_marker: String,
#[deserr(default, error = DeserrJsonError<InvalidSearchMatchingStrategy>, default)] #[deserr(default, error = DeserrJsonError<InvalidSearchMatchingStrategy>, default)]
pub matching_strategy: MatchingStrategy, pub matching_strategy: MatchingStrategy,
#[deserr(default, error = DeserrJsonError<InvalidRestrictSearchableAttributes>, default)] #[deserr(default, error = DeserrJsonError<InvalidAttributesToSearchOn>, default)]
pub restrict_searchable_attributes: Option<Vec<String>>, pub attributes_to_search_on: Option<Vec<String>>,
} }
impl SearchQuery { impl SearchQuery {
@ -130,8 +130,8 @@ pub struct SearchQueryWithIndex {
pub crop_marker: String, pub crop_marker: String,
#[deserr(default, error = DeserrJsonError<InvalidSearchMatchingStrategy>, default)] #[deserr(default, error = DeserrJsonError<InvalidSearchMatchingStrategy>, default)]
pub matching_strategy: MatchingStrategy, pub matching_strategy: MatchingStrategy,
#[deserr(default, error = DeserrJsonError<InvalidRestrictSearchableAttributes>, default)] #[deserr(default, error = DeserrJsonError<InvalidAttributesToSearchOn>, default)]
pub restrict_searchable_attributes: Option<Vec<String>>, pub attributes_to_search_on: Option<Vec<String>>,
} }
impl SearchQueryWithIndex { impl SearchQueryWithIndex {
@ -157,7 +157,7 @@ impl SearchQueryWithIndex {
highlight_post_tag, highlight_post_tag,
crop_marker, crop_marker,
matching_strategy, matching_strategy,
restrict_searchable_attributes, attributes_to_search_on,
} = self; } = self;
( (
index_uid, index_uid,
@ -181,7 +181,7 @@ impl SearchQueryWithIndex {
highlight_post_tag, highlight_post_tag,
crop_marker, crop_marker,
matching_strategy, matching_strategy,
restrict_searchable_attributes, attributes_to_search_on,
// do not use ..Default::default() here, // do not use ..Default::default() here,
// rather add any missing field from `SearchQuery` to `SearchQueryWithIndex` // rather add any missing field from `SearchQuery` to `SearchQueryWithIndex`
}, },
@ -297,7 +297,7 @@ pub fn perform_search(
search.query(query); 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); search.searchable_attributes(searchable);
} }

View File

@ -39,7 +39,7 @@ async fn simple_search_on_title() {
// simple search should return 2 documents (ids: 2 and 3). // simple search should return 2 documents (ids: 2 and 3).
index index
.search( .search(
json!({"q": "Captain Marvel", "restrictSearchableAttributes": ["title"]}), json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"]}),
|response, code| { |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!(response["hits"].as_array().unwrap().len(), 2); 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). // simple search should return 2 documents (ids: 2 and 3).
index index
.search( .search(json!({"q": "Captain Mar", "attributesToSearchOn": ["title"]}), |response, code| {
json!({"q": "Captain Mar", "restrictSearchableAttributes": ["title"]}),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!(response["hits"].as_array().unwrap().len(), 2); assert_eq!(response["hits"].as_array().unwrap().len(), 2);
}, })
)
.await; .await;
} }
@ -71,7 +68,7 @@ async fn simple_search_on_title_matching_strategy_all() {
let index = index_with_documents(&server, &SIMPLE_SEARCH_DOCUMENTS).await; let index = index_with_documents(&server, &SIMPLE_SEARCH_DOCUMENTS).await;
// simple search matching strategy all should only return 1 document (ids: 2). // simple search matching strategy all should only return 1 document (ids: 2).
index 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!(code, 200, "{}", response);
assert_eq!(response["hits"].as_array().unwrap().len(), 1); 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. // simple search on unknown field shouldn't return any document.
index index
.search( .search(
json!({"q": "Captain Marvel", "restrictSearchableAttributes": ["unknown"]}), json!({"q": "Captain Marvel", "attributesToSearchOn": ["unknown"]}),
|response, code| { |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!(response["hits"].as_array().unwrap().len(), 0); 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; let index = index_with_documents(&server, &SIMPLE_SEARCH_DOCUMENTS).await;
// simple search on no field shouldn't return any document. // simple search on no field shouldn't return any document.
index index
.search( .search(json!({"q": "Captain Marvel", "attributesToSearchOn": []}), |response, code| {
json!({"q": "Captain Marvel", "restrictSearchableAttributes": []}),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!(response["hits"].as_array().unwrap().len(), 0); assert_eq!(response["hits"].as_array().unwrap().len(), 0);
}, })
)
.await; .await;
} }
@ -118,7 +112,7 @@ async fn word_ranking_rule_order() {
// Document 3 should appear before document 2. // Document 3 should appear before document 2.
index index
.search( .search(
json!({"q": "Captain Marvel", "restrictSearchableAttributes": ["title"], "attributesToRetrieve": ["id"]}), json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "attributesToRetrieve": ["id"]}),
|response, code| { |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
@ -143,7 +137,7 @@ async fn word_ranking_rule_order_exact_words() {
// simple search should return 2 documents (ids: 2 and 3). // simple search should return 2 documents (ids: 2 and 3).
index index
.search( .search(
json!({"q": "Captain Marvel", "restrictSearchableAttributes": ["title"], "attributesToRetrieve": ["id"]}), json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "attributesToRetrieve": ["id"]}),
|response, code| { |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
@ -179,7 +173,7 @@ async fn typo_ranking_rule_order() {
// Document 2 should appear before document 1. // Document 2 should appear before document 1.
index 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!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"], response["hits"],
@ -215,7 +209,7 @@ async fn attributes_ranking_rule_order() {
// Document 2 should appear before document 1. // Document 2 should appear before document 1.
index 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!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"], response["hits"],
@ -249,7 +243,7 @@ async fn exactness_ranking_rule_order() {
// Document 2 should appear before document 1. // Document 2 should appear before document 1.
index 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!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"], response["hits"],