@@ -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,77 @@ 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
+ pub federation : Option < FederationOptions > ,
679
+ }
680
+
681
+ /// The `federation` field of the multi search API.
682
+ /// See [the docs](https://www.meilisearch.com/docs/reference/api/multi_search#federation).
683
+ #[ derive( Debug , Serialize , Clone , Default ) ]
684
+ #[ serde( rename_all = "camelCase" ) ]
685
+ pub struct FederationOptions {
686
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
687
+ pub offset : Option < usize > ,
688
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
689
+ pub limit : Option < usize > ,
690
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
691
+ pub facets_by_index : Option < HashMap < String , Vec < String > > > ,
692
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
693
+ pub merge_facets : Option < bool > ,
694
+ }
695
+
696
+ #[ allow( missing_docs) ]
697
+ impl < ' a , ' b , Http : HttpClient > FederatedMultiSearchQuery < ' a , ' b , Http > {
698
+ /// Execute the query and fetch the results.
699
+ pub async fn execute < T : ' static + DeserializeOwned + Send + Sync > (
700
+ & ' a self ,
701
+ ) -> Result < FederatedMultiSearchResponse < T > , Error > {
702
+ self . client
703
+ . execute_federated_multi_search_query :: < T > ( self )
704
+ . await
705
+ }
706
+ }
707
+
708
+ /// Returned by federated multi search.
709
+ #[ derive( Debug , Deserialize , Clone ) ]
710
+ #[ serde( rename_all = "camelCase" ) ]
711
+ pub struct FederatedMultiSearchResponse < T > {
712
+ /// Merged results of the query.
713
+ pub hits : Vec < SearchResult < T > > ,
714
+
715
+ // TODO: are offset, limit and estimated_total_hits really non-optional? In
716
+ // my tests they are always returned, but that's not a proof.
717
+ /// Number of documents skipped.
718
+ pub offset : usize ,
719
+ /// Number of results returned.
720
+ pub limit : usize ,
721
+ /// Estimated total number of matches.
722
+ pub estimated_total_hits : usize ,
723
+
724
+ /// Distribution of the given facets.
725
+ pub facet_distribution : Option < HashMap < String , HashMap < String , usize > > > ,
726
+ /// facet stats of the numerical facets requested in the `facet` search parameter.
727
+ pub facet_stats : Option < HashMap < String , FacetStats > > ,
728
+ /// Processing time of the query.
729
+ pub processing_time_ms : usize ,
730
+ }
731
+
732
+ /// Returned for each hit in `_federation` when doing federated multi search.
733
+ #[ derive( Debug , Deserialize , Clone ) ]
734
+ #[ serde( rename_all = "camelCase" ) ]
735
+ pub struct FederationHitInfo {
736
+ pub index_uid : String ,
737
+ pub queries_position : usize ,
738
+ // TOOD: not mentioned in the docs, is that optional?
739
+ pub weighted_ranking_score : f32 ,
740
+ }
741
+
658
742
#[ cfg( test) ]
659
743
mod tests {
660
744
use crate :: {
0 commit comments