Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meilisearch#499 (attributesToSearchOn) #510

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,15 @@ search_parameter_guide_query_1: |-
.execute()
.await
.unwrap();
search_parameter_guide_attributes_to_search_on_1: |-
let results: SearchResults<Movie> = client
.index("movies")
.search()
.with_query("adventure")
.with_attributes_to_search_on(&["overview"])
.execute()
.await
.unwrap();
search_parameter_guide_offset_1: |-
let results: SearchResults<Movie> = client
.index("movies")
Expand Down
29 changes: 29 additions & 0 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]>,
Expand Down Expand Up @@ -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<Document> = 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?;
Expand Down