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