@@ -66,6 +66,9 @@ pub struct SearchResult<T> {
66
66
pub ranking_score : Option < f64 > ,
67
67
#[ serde( rename = "_rankingScoreDetails" ) ]
68
68
pub ranking_score_details : Option < Map < String , Value > > ,
69
+ /// Only returned for federated multi search.
70
+ #[ serde( rename = "_federation" ) ]
71
+ pub federation : Option < FederationHitInfo > ,
69
72
}
70
73
71
74
#[ derive( Deserialize , Debug , Clone ) ]
@@ -624,7 +627,6 @@ pub struct MultiSearchQuery<'a, 'b, Http: HttpClient = DefaultHttpClient> {
624
627
pub queries : Vec < SearchQuery < ' b , Http > > ,
625
628
}
626
629
627
-
628
630
#[ allow( missing_docs) ]
629
631
impl < ' a , ' b , Http : HttpClient > MultiSearchQuery < ' a , ' b , Http > {
630
632
#[ must_use]
@@ -642,6 +644,17 @@ impl<'a, 'b, Http: HttpClient> MultiSearchQuery<'a, 'b, Http> {
642
644
self . queries . push ( search_query) ;
643
645
self
644
646
}
647
+ /// Adds the `federation` parameter, making the search a federated search.
648
+ pub fn with_federation (
649
+ self ,
650
+ federation : FederationOptions ,
651
+ ) -> FederatedMultiSearchQuery < ' a , ' b , Http > {
652
+ FederatedMultiSearchQuery {
653
+ client : self . client ,
654
+ queries : self . queries ,
655
+ federation : Some ( federation) ,
656
+ }
657
+ }
645
658
646
659
/// Execute the query and fetch the results.
647
660
pub async fn execute < T : ' static + DeserializeOwned + Send + Sync > (
@@ -655,6 +668,78 @@ pub struct MultiSearchResponse<T> {
655
668
pub results : Vec < SearchResults < T > > ,
656
669
}
657
670
671
+ #[ derive( Debug , Serialize , Clone ) ]
672
+ #[ serde( rename_all = "camelCase" ) ]
673
+ pub struct FederatedMultiSearchQuery < ' a , ' b , Http : HttpClient = DefaultHttpClient > {
674
+ #[ serde( skip_serializing) ]
675
+ client : & ' a Client < Http > ,
676
+ #[ serde( bound( serialize = "" ) ) ]
677
+ pub queries : Vec < SearchQuery < ' b , Http > > ,
678
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
679
+ pub federation : Option < FederationOptions > ,
680
+ }
681
+
682
+ /// The `federation` field of the multi search API.
683
+ /// See [the docs](https://www.meilisearch.com/docs/reference/api/multi_search#federation).
684
+ #[ derive( Debug , Serialize , Clone , Default ) ]
685
+ #[ serde( rename_all = "camelCase" ) ]
686
+ pub struct FederationOptions {
687
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
688
+ pub offset : Option < usize > ,
689
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
690
+ pub limit : Option < usize > ,
691
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
692
+ pub facets_by_index : Option < HashMap < String , Vec < String > > > ,
693
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
694
+ pub merge_facets : Option < bool > ,
695
+ }
696
+
697
+ #[ allow( missing_docs) ]
698
+ impl < ' a , Http : HttpClient > FederatedMultiSearchQuery < ' a , ' _ , Http > {
699
+ /// Execute the query and fetch the results.
700
+ pub async fn execute < T : ' static + DeserializeOwned + Send + Sync > (
701
+ & ' a self ,
702
+ ) -> Result < FederatedMultiSearchResponse < T > , Error > {
703
+ self . client
704
+ . execute_federated_multi_search_query :: < T > ( self )
705
+ . await
706
+ }
707
+ }
708
+
709
+ /// Returned by federated multi search.
710
+ #[ derive( Debug , Deserialize , Clone ) ]
711
+ #[ serde( rename_all = "camelCase" ) ]
712
+ pub struct FederatedMultiSearchResponse < T > {
713
+ /// Merged results of the query.
714
+ pub hits : Vec < SearchResult < T > > ,
715
+
716
+ // TODO: are offset, limit and estimated_total_hits really non-optional? In
717
+ // my tests they are always returned, but that's not a proof.
718
+ /// Number of documents skipped.
719
+ pub offset : usize ,
720
+ /// Number of results returned.
721
+ pub limit : usize ,
722
+ /// Estimated total number of matches.
723
+ pub estimated_total_hits : usize ,
724
+
725
+ /// Distribution of the given facets.
726
+ pub facet_distribution : Option < HashMap < String , HashMap < String , usize > > > ,
727
+ /// facet stats of the numerical facets requested in the `facet` search parameter.
728
+ pub facet_stats : Option < HashMap < String , FacetStats > > ,
729
+ /// Processing time of the query.
730
+ pub processing_time_ms : usize ,
731
+ }
732
+
733
+ /// Returned for each hit in `_federation` when doing federated multi search.
734
+ #[ derive( Debug , Deserialize , Clone ) ]
735
+ #[ serde( rename_all = "camelCase" ) ]
736
+ pub struct FederationHitInfo {
737
+ pub index_uid : String ,
738
+ pub queries_position : usize ,
739
+ // TOOD: not mentioned in the docs, is that optional?
740
+ pub weighted_ranking_score : f32 ,
741
+ }
742
+
658
743
#[ cfg( test) ]
659
744
mod tests {
660
745
use crate :: {
0 commit comments