@@ -338,6 +338,10 @@ pub struct SearchQuery<'a, Http: HttpClient> {
338338
339339 #[ serde( skip_serializing_if = "Option::is_none" ) ]
340340 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 > ,
341345}
342346
343347#[ allow( missing_docs) ]
@@ -367,6 +371,7 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
367371 show_ranking_score_details : None ,
368372 matching_strategy : None ,
369373 index_uid : None ,
374+ distinct : None ,
370375 }
371376 }
372377 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> {
559564 self . index_uid = Some ( & self . index . uid ) ;
560565 self
561566 }
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+ }
562571 pub fn build ( & mut self ) -> SearchQuery < ' a , Http > {
563572 self . clone ( )
564573 }
@@ -632,6 +641,7 @@ mod tests {
632641 use meilisearch_test_macro:: meilisearch_test;
633642 use serde:: { Deserialize , Serialize } ;
634643 use serde_json:: { json, Map , Value } ;
644+ use time:: format_description:: well_known:: iso8601:: DateKind ;
635645
636646 #[ derive( Debug , Serialize , Deserialize , PartialEq ) ]
637647 struct Nested {
@@ -1182,6 +1192,20 @@ mod tests {
11821192 Ok ( ( ) )
11831193 }
11841194
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+
11851209 #[ meilisearch_test]
11861210 async fn test_generate_tenant_token_from_client (
11871211 client : Client ,
0 commit comments