@@ -45,6 +45,9 @@ pub struct SearchResult<T> {
45
45
/// The object that contains information about the matches.
46
46
#[ serde( rename = "_matchesPosition" ) ]
47
47
pub matches_position : Option < HashMap < String , Vec < MatchRange > > > ,
48
+ /// The relevancy score of the match.
49
+ #[ serde( rename = "_rankingScore" ) ]
50
+ pub ranking_score : Option < f64 > ,
48
51
}
49
52
50
53
#[ derive( Deserialize , Debug , Clone ) ]
@@ -302,6 +305,12 @@ pub struct SearchQuery<'a> {
302
305
#[ serde( skip_serializing_if = "Option::is_none" ) ]
303
306
pub show_matches_position : Option < bool > ,
304
307
308
+ /// Defines whether to show the relevancy score of the match.
309
+ ///
310
+ /// **Default: `false`**
311
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
312
+ pub show_ranking_score : Option < bool > ,
313
+
305
314
/// Defines the strategy on how to handle queries containing multiple words.
306
315
#[ serde( skip_serializing_if = "Option::is_none" ) ]
307
316
pub matching_strategy : Option < MatchingStrategies > ,
@@ -331,6 +340,7 @@ impl<'a> SearchQuery<'a> {
331
340
highlight_pre_tag : None ,
332
341
highlight_post_tag : None ,
333
342
show_matches_position : None ,
343
+ show_ranking_score : None ,
334
344
matching_strategy : None ,
335
345
index_uid : None ,
336
346
}
@@ -480,6 +490,13 @@ impl<'a> SearchQuery<'a> {
480
490
self . show_matches_position = Some ( show_matches_position) ;
481
491
self
482
492
}
493
+ pub fn with_show_ranking_score < ' b > (
494
+ & ' b mut self ,
495
+ show_ranking_score : bool ,
496
+ ) -> & ' b mut SearchQuery < ' a > {
497
+ self . show_ranking_score = Some ( show_ranking_score) ;
498
+ self
499
+ }
483
500
pub fn with_matching_strategy < ' b > (
484
501
& ' b mut self ,
485
502
matching_strategy : MatchingStrategies ,
@@ -1027,6 +1044,18 @@ mod tests {
1027
1044
Ok ( ( ) )
1028
1045
}
1029
1046
1047
+ #[ meilisearch_test]
1048
+ async fn test_query_show_ranking_score ( client : Client , index : Index ) -> Result < ( ) , Error > {
1049
+ setup_test_index ( & client, & index) . await ?;
1050
+
1051
+ let mut query = SearchQuery :: new ( & index) ;
1052
+ query. with_query ( "dolor text" ) ;
1053
+ query. with_show_ranking_score ( true ) ;
1054
+ let results: SearchResults < Document > = index. execute_query ( & query) . await ?;
1055
+ assert ! ( results. hits[ 0 ] . ranking_score. is_some( ) ) ;
1056
+ Ok ( ( ) )
1057
+ }
1058
+
1030
1059
#[ meilisearch_test]
1031
1060
async fn test_phrase_search ( client : Client , index : Index ) -> Result < ( ) , Error > {
1032
1061
setup_test_index ( & client, & index) . await ?;
0 commit comments