@@ -55,6 +55,9 @@ pub struct SearchResult<T> {
55
55
pub ranking_score : Option < f64 > ,
56
56
#[ serde( rename = "_rankingScoreDetails" ) ]
57
57
pub ranking_score_details : Option < Map < String , Value > > ,
58
+ /// Only returned for federated multi search.
59
+ #[ serde( rename = "_federation" ) ]
60
+ pub federation : Option < FederationHitInfo > ,
58
61
}
59
62
60
63
#[ derive( Deserialize , Debug , Clone ) ]
@@ -604,7 +607,6 @@ pub struct MultiSearchQuery<'a, 'b, Http: HttpClient = DefaultHttpClient> {
604
607
pub queries : Vec < SearchQuery < ' b , Http > > ,
605
608
}
606
609
607
-
608
610
#[ allow( missing_docs) ]
609
611
impl < ' a , ' b , Http : HttpClient > MultiSearchQuery < ' a , ' b , Http > {
610
612
#[ must_use]
@@ -622,6 +624,17 @@ impl<'a, 'b, Http: HttpClient> MultiSearchQuery<'a, 'b, Http> {
622
624
self . queries . push ( search_query) ;
623
625
self
624
626
}
627
+ /// Adds the `federation` parameter, making the search a federated search.
628
+ pub fn with_federation (
629
+ self ,
630
+ federation : FederationOptions ,
631
+ ) -> FederatedMultiSearchQuery < ' a , ' b , Http > {
632
+ FederatedMultiSearchQuery {
633
+ client : self . client ,
634
+ queries : self . queries ,
635
+ federation : Some ( federation) ,
636
+ }
637
+ }
625
638
626
639
/// Execute the query and fetch the results.
627
640
pub async fn execute < T : ' static + DeserializeOwned + Send + Sync > (
@@ -635,6 +648,77 @@ pub struct MultiSearchResponse<T> {
635
648
pub results : Vec < SearchResults < T > > ,
636
649
}
637
650
651
+ #[ derive( Debug , Serialize , Clone ) ]
652
+ #[ serde( rename_all = "camelCase" ) ]
653
+ pub struct FederatedMultiSearchQuery < ' a , ' b , Http : HttpClient = DefaultHttpClient > {
654
+ #[ serde( skip_serializing) ]
655
+ client : & ' a Client < Http > ,
656
+ #[ serde( bound( serialize = "" ) ) ]
657
+ pub queries : Vec < SearchQuery < ' b , Http > > ,
658
+ pub federation : Option < FederationOptions > ,
659
+ }
660
+
661
+ /// The `federation` field of the multi search API.
662
+ /// See [the docs](https://www.meilisearch.com/docs/reference/api/multi_search#federation).
663
+ #[ derive( Debug , Serialize , Clone , Default ) ]
664
+ #[ serde( rename_all = "camelCase" ) ]
665
+ pub struct FederationOptions {
666
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
667
+ pub offset : Option < usize > ,
668
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
669
+ pub limit : Option < usize > ,
670
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
671
+ pub facets_by_index : Option < HashMap < String , Vec < String > > > ,
672
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
673
+ pub merge_facets : Option < bool > ,
674
+ }
675
+
676
+ #[ allow( missing_docs) ]
677
+ impl < ' a , ' b , Http : HttpClient > FederatedMultiSearchQuery < ' a , ' b , Http > {
678
+ /// Execute the query and fetch the results.
679
+ pub async fn execute < T : ' static + DeserializeOwned + Send + Sync > (
680
+ & ' a self ,
681
+ ) -> Result < FederatedMultiSearchResponse < T > , Error > {
682
+ self . client
683
+ . execute_federated_multi_search_query :: < T > ( self )
684
+ . await
685
+ }
686
+ }
687
+
688
+ /// Returned by federated multi search.
689
+ #[ derive( Debug , Deserialize , Clone ) ]
690
+ #[ serde( rename_all = "camelCase" ) ]
691
+ pub struct FederatedMultiSearchResponse < T > {
692
+ /// Merged results of the query.
693
+ pub hits : Vec < SearchResult < T > > ,
694
+
695
+ // TODO: are offset, limit and estimated_total_hits really non-optional? In
696
+ // my tests they are always returned, but that's not a proof.
697
+ /// Number of documents skipped.
698
+ pub offset : usize ,
699
+ /// Number of results returned.
700
+ pub limit : usize ,
701
+ /// Estimated total number of matches.
702
+ pub estimated_total_hits : usize ,
703
+
704
+ /// Distribution of the given facets.
705
+ pub facet_distribution : Option < HashMap < String , HashMap < String , usize > > > ,
706
+ /// facet stats of the numerical facets requested in the `facet` search parameter.
707
+ pub facet_stats : Option < HashMap < String , FacetStats > > ,
708
+ /// Processing time of the query.
709
+ pub processing_time_ms : usize ,
710
+ }
711
+
712
+ /// Returned for each hit in `_federation` when doing federated multi search.
713
+ #[ derive( Debug , Deserialize , Clone ) ]
714
+ #[ serde( rename_all = "camelCase" ) ]
715
+ pub struct FederationHitInfo {
716
+ pub index_uid : String ,
717
+ pub queries_position : usize ,
718
+ // TOOD: not mentioned in the docs, is that optional?
719
+ pub weighted_ranking_score : f32 ,
720
+ }
721
+
638
722
#[ cfg( test) ]
639
723
mod tests {
640
724
use crate :: {
0 commit comments