@@ -246,6 +246,13 @@ pub struct SearchQuery<'a> {
246
246
/// Attributes to sort.
247
247
#[ serde( skip_serializing_if = "Option::is_none" ) ]
248
248
pub sort : Option < & ' a [ & ' a str ] > ,
249
+ /// Attributes to perform the search on.
250
+ ///
251
+ /// Specify the subset of searchableAttributes for a search without modifying Meilisearch’s index settings.
252
+ ///
253
+ /// **Default: all searchable attributes found in the documents.**
254
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
255
+ pub attributes_to_search_on : Option < & ' a [ & ' a str ] > ,
249
256
/// Attributes to display in the returned documents.
250
257
///
251
258
/// 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> {
323
330
filter : None ,
324
331
sort : None ,
325
332
facets : None ,
333
+ attributes_to_search_on : None ,
326
334
attributes_to_retrieve : None ,
327
335
attributes_to_crop : None ,
328
336
crop_length : None ,
@@ -430,6 +438,13 @@ impl<'a> SearchQuery<'a> {
430
438
self . sort = Some ( sort) ;
431
439
self
432
440
}
441
+ pub fn with_attributes_to_search_on < ' b > (
442
+ & ' b mut self ,
443
+ attributes_to_search_on : & ' a [ & ' a str ] ,
444
+ ) -> & ' b mut SearchQuery < ' a > {
445
+ self . attributes_to_search_on = Some ( attributes_to_search_on) ;
446
+ self
447
+ }
433
448
pub fn with_attributes_to_retrieve < ' b > (
434
449
& ' b mut self ,
435
450
attributes_to_retrieve : Selectors < & ' a [ & ' a str ] > ,
@@ -830,6 +845,20 @@ mod tests {
830
845
Ok ( ( ) )
831
846
}
832
847
848
+ #[ meilisearch_test]
849
+ async fn test_query_attributes_to_search_on ( client : Client , index : Index ) -> Result < ( ) , Error > {
850
+ setup_test_index ( & client, & index) . await ?;
851
+
852
+ let results: SearchResults < Document > = index
853
+ . search ( )
854
+ . with_query ( "title" )
855
+ . with_attributes_to_search_on ( & [ "kind" ] )
856
+ . execute ( )
857
+ . await ?;
858
+ assert_eq ! ( results. hits. len( ) , 8 ) ;
859
+ Ok ( ( ) )
860
+ }
861
+
833
862
#[ meilisearch_test]
834
863
async fn test_query_sort ( client : Client , index : Index ) -> Result < ( ) , Error > {
835
864
setup_test_index ( & client, & index) . await ?;
0 commit comments