@@ -135,6 +135,9 @@ pub struct SearchResults<T> {
135135 skip_serializing_if = "Option::is_none"
136136 ) ]
137137 pub query_vector : Option < Vec < f32 > > ,
138+ /// The search query's performance trace.
139+ /// Returned when `showPerformanceDetails` is enabled.
140+ pub performance_details : Option < Value > ,
138141}
139142
140143fn serialize_attributes_to_crop_with_wildcard < S : Serializer > (
@@ -424,6 +427,12 @@ pub struct SearchQuery<'a, Http: HttpClient> {
424427
425428 #[ serde( skip_serializing_if = "Option::is_none" ) ]
426429 pub ( crate ) federation_options : Option < QueryFederationOptions > ,
430+
431+ /// Defines whether to return performance trace.
432+ ///
433+ /// **Default: `false`**
434+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
435+ pub show_performance_details : Option < bool > ,
427436}
428437
429438#[ derive( Debug , Serialize , Clone ) ]
@@ -473,6 +482,7 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
473482 ranking_score_threshold : None ,
474483 locales : None ,
475484 federation_options : None ,
485+ show_performance_details : None ,
476486 }
477487 }
478488
@@ -752,6 +762,15 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
752762 self
753763 }
754764
765+ /// Request performance details in the response.
766+ pub fn with_show_performance_details < ' b > (
767+ & ' b mut self ,
768+ show_performance_details : bool ,
769+ ) -> & ' b mut SearchQuery < ' a , Http > {
770+ self . show_performance_details = Some ( show_performance_details) ;
771+ self
772+ }
773+
755774 /// Execute the query and fetch the results.
756775 pub async fn execute < T : ' static + DeserializeOwned + Send + Sync > (
757776 & ' a self ,
@@ -880,6 +899,10 @@ pub struct FederationOptions {
880899 /// Request to merge the facets to enforce a maximum number of values per facet.
881900 #[ serde( skip_serializing_if = "Option::is_none" ) ]
882901 pub merge_facets : Option < MergeFacets > ,
902+
903+ /// Request performance details in the response.
904+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
905+ pub show_performance_details : Option < bool > ,
883906}
884907
885908impl < ' a , Http : HttpClient > FederatedMultiSearchQuery < ' a , ' _ , Http > {
@@ -929,6 +952,9 @@ pub struct FederatedMultiSearchResponse<T> {
929952
930953 /// Indicates which remote requests failed and why
931954 pub remote_errors : Option < HashMap < String , MeilisearchError > > ,
955+
956+ /// The performance trace for the query.
957+ pub performance_details : Option < Value > ,
932958}
933959
934960/// Returned for each hit in `_federation` when doing federated multi search.
@@ -2305,4 +2331,70 @@ pub(crate) mod tests {
23052331 assert_eq ! ( res. facet_hits[ 0 ] . count, 7 ) ;
23062332 Ok ( ( ) )
23072333 }
2334+
2335+ #[ meilisearch_test]
2336+ async fn test_search_with_show_performance_details (
2337+ client : Client ,
2338+ index : Index ,
2339+ ) -> Result < ( ) , Error > {
2340+ setup_test_index ( & client, & index) . await ?;
2341+
2342+ let res = index
2343+ . search ( )
2344+ . with_show_performance_details ( true )
2345+ . with_query ( "Lorem" )
2346+ . execute :: < Value > ( )
2347+ . await ?;
2348+
2349+ assert ! ( res. performance_details. is_some( ) ) ;
2350+
2351+ Ok ( ( ) )
2352+ }
2353+
2354+ #[ meilisearch_test]
2355+ async fn test_multi_search_with_show_performance_details (
2356+ client : Client ,
2357+ index : Index ,
2358+ ) -> Result < ( ) , Error > {
2359+ setup_test_index ( & client, & index) . await ?;
2360+ let search_query_1 = SearchQuery :: new ( & index)
2361+ . with_query ( "Sorcerer's Stone" )
2362+ . with_show_performance_details ( true )
2363+ . build ( ) ;
2364+ let search_query_2 = SearchQuery :: new ( & index)
2365+ . with_query ( "Chamber of Secrets" )
2366+ . build ( ) ;
2367+
2368+ let response = client
2369+ . multi_search ( )
2370+ . with_search_query ( search_query_1)
2371+ . with_search_query ( search_query_2)
2372+ . execute :: < Document > ( )
2373+ . await
2374+ . unwrap ( ) ;
2375+
2376+ assert ! ( response. results[ 0 ] . performance_details. is_some( ) ) ;
2377+ Ok ( ( ) )
2378+ }
2379+
2380+ #[ meilisearch_test]
2381+ async fn test_federated_multi_search_with_show_performance_details (
2382+ client : Client ,
2383+ test_index : Index ,
2384+ ) -> Result < ( ) , Error > {
2385+ setup_test_index ( & client, & test_index) . await ?;
2386+
2387+ let response = client
2388+ . multi_search ( )
2389+ . with_federation ( FederationOptions {
2390+ show_performance_details : Some ( true ) ,
2391+ ..Default :: default ( )
2392+ } )
2393+ . execute :: < Value > ( )
2394+ . await ?;
2395+
2396+ assert ! ( response. performance_details. is_some( ) ) ;
2397+
2398+ Ok ( ( ) )
2399+ }
23082400}
0 commit comments