@@ -338,6 +338,10 @@ pub struct SearchQuery<'a, Http: HttpClient> {
338
338
339
339
#[ serde( skip_serializing_if = "Option::is_none" ) ]
340
340
pub ( crate ) index_uid : Option < & ' a str > ,
341
+
342
+ ///Defines one attribute in the filterableAttributes list as a distinct attribute.
343
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
344
+ pub ( crate ) distinct : Option < & ' a str > ,
341
345
}
342
346
343
347
#[ allow( missing_docs) ]
@@ -367,6 +371,7 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
367
371
show_ranking_score_details : None ,
368
372
matching_strategy : None ,
369
373
index_uid : None ,
374
+ distinct : None ,
370
375
}
371
376
}
372
377
pub fn with_query < ' b > ( & ' b mut self , query : & ' a str ) -> & ' b mut SearchQuery < ' a , Http > {
@@ -559,6 +564,10 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
559
564
self . index_uid = Some ( & self . index . uid ) ;
560
565
self
561
566
}
567
+ pub fn with_distinct < ' b > ( & ' b mut self , distinct : & ' a str ) -> & ' b mut SearchQuery < ' a , Http > {
568
+ self . distinct = Some ( distinct) ;
569
+ self
570
+ }
562
571
pub fn build ( & mut self ) -> SearchQuery < ' a , Http > {
563
572
self . clone ( )
564
573
}
@@ -632,6 +641,7 @@ mod tests {
632
641
use meilisearch_test_macro:: meilisearch_test;
633
642
use serde:: { Deserialize , Serialize } ;
634
643
use serde_json:: { json, Map , Value } ;
644
+ use time:: format_description:: well_known:: iso8601:: DateKind ;
635
645
636
646
#[ derive( Debug , Serialize , Deserialize , PartialEq ) ]
637
647
struct Nested {
@@ -1182,6 +1192,20 @@ mod tests {
1182
1192
Ok ( ( ) )
1183
1193
}
1184
1194
1195
+ #[ meilisearch_test]
1196
+ async fn test_distinct ( client : Client , index : Index ) -> Result < ( ) , Error > {
1197
+ setup_test_index ( & client, & index) . await ?;
1198
+
1199
+ let results = SearchQuery :: new ( & index)
1200
+ . with_distinct ( "kind" )
1201
+ . execute :: < Document > ( )
1202
+ . await
1203
+ . unwrap ( ) ;
1204
+
1205
+ assert_eq ! ( results. hits. len( ) , 2 ) ;
1206
+ Ok ( ( ) )
1207
+ }
1208
+
1185
1209
#[ meilisearch_test]
1186
1210
async fn test_generate_tenant_token_from_client (
1187
1211
client : Client ,
0 commit comments