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