diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index b840d99e..77170ae5 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -692,6 +692,15 @@ search_parameter_guide_query_1: |- .execute() .await .unwrap(); +search_parameter_guide_attributes_to_search_on_1: |- + let results: SearchResults = client + .index("movies") + .search() + .with_query("adventure") + .with_attributes_to_search_on(&["overview"]) + .execute() + .await + .unwrap(); search_parameter_guide_offset_1: |- let results: SearchResults = client .index("movies") diff --git a/src/search.rs b/src/search.rs index 3f98ed41..3d57f73d 100644 --- a/src/search.rs +++ b/src/search.rs @@ -246,6 +246,13 @@ pub struct SearchQuery<'a> { /// Attributes to sort. #[serde(skip_serializing_if = "Option::is_none")] pub sort: Option<&'a [&'a str]>, + /// Attributes to perform the search on. + /// + /// Specify the subset of searchableAttributes for a search without modifying Meilisearch’s index settings. + /// + /// **Default: all searchable attributes found in the documents.** + #[serde(skip_serializing_if = "Option::is_none")] + pub attributes_to_search_on: Option<&'a [&'a str]>, /// Attributes to display in the returned documents. /// /// Can be set to a [wildcard value](enum.Selectors.html#variant.All) that will select all existing attributes. @@ -323,6 +330,7 @@ impl<'a> SearchQuery<'a> { filter: None, sort: None, facets: None, + attributes_to_search_on: None, attributes_to_retrieve: None, attributes_to_crop: None, crop_length: None, @@ -430,6 +438,13 @@ impl<'a> SearchQuery<'a> { self.sort = Some(sort); self } + pub fn with_attributes_to_search_on<'b>( + &'b mut self, + attributes_to_search_on: &'a [&'a str], + ) -> &'b mut SearchQuery<'a> { + self.attributes_to_search_on = Some(attributes_to_search_on); + self + } pub fn with_attributes_to_retrieve<'b>( &'b mut self, attributes_to_retrieve: Selectors<&'a [&'a str]>, @@ -830,6 +845,20 @@ mod tests { Ok(()) } + #[meilisearch_test] + async fn test_query_attributes_to_search_on(client: Client, index: Index) -> Result<(), Error> { + setup_test_index(&client, &index).await?; + + let results: SearchResults = index + .search() + .with_query("title") + .with_attributes_to_search_on(&["kind"]) + .execute() + .await?; + assert_eq!(results.hits.len(), 8); + Ok(()) + } + #[meilisearch_test] async fn test_query_sort(client: Client, index: Index) -> Result<(), Error> { setup_test_index(&client, &index).await?;