Skip to content

Commit 45a7452

Browse files
added showRankingScoreDetails parameter at search
1 parent 9e57f3e commit 45a7452

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/search.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ pub struct SearchResult<T> {
5151
/// The relevancy score of the match.
5252
#[serde(rename = "_rankingScore")]
5353
pub ranking_score: Option<f64>,
54+
#[serde(rename = "_rankingScoreDetails")]
55+
pub ranking_score_details: Option<Map<String, Value>>,
5456
}
5557

5658
#[derive(Deserialize, Debug, Clone)]
@@ -322,6 +324,12 @@ pub struct SearchQuery<'a, Http: HttpClient> {
322324
#[serde(skip_serializing_if = "Option::is_none")]
323325
pub show_ranking_score: Option<bool>,
324326

327+
///Adds a detailed global ranking score field to each document.
328+
///
329+
/// **Default: `false`**
330+
#[serde(skip_serializing_if = "Option::is_none")]
331+
pub show_ranking_score_details: Option<bool>,
332+
325333
/// Defines the strategy on how to handle queries containing multiple words.
326334
#[serde(skip_serializing_if = "Option::is_none")]
327335
pub matching_strategy: Option<MatchingStrategies>,
@@ -354,6 +362,7 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
354362
highlight_post_tag: None,
355363
show_matches_position: None,
356364
show_ranking_score: None,
365+
show_ranking_score_details: None,
357366
matching_strategy: None,
358367
index_uid: None,
359368
}
@@ -528,6 +537,15 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
528537
self.show_ranking_score = Some(show_ranking_score);
529538
self
530539
}
540+
541+
pub fn with_show_ranking_score_details<'b>(
542+
&'b mut self,
543+
show_ranking_score_details: bool,
544+
) -> &'b mut SearchQuery<'a, Http> {
545+
self.show_ranking_score_details = Some(show_ranking_score_details);
546+
self
547+
}
548+
531549
pub fn with_matching_strategy<'b>(
532550
&'b mut self,
533551
matching_strategy: MatchingStrategies,
@@ -1090,6 +1108,18 @@ mod tests {
10901108
Ok(())
10911109
}
10921110

1111+
#[meilisearch_test]
1112+
async fn test_query_show_ranking_score_details(client: Client, index: Index) -> Result<(), Error> {
1113+
setup_test_index(&client, &index).await?;
1114+
1115+
let mut query = SearchQuery::new(&index);
1116+
query.with_query("dolor text");
1117+
query.with_show_ranking_score_details(true);
1118+
let results: SearchResults<Document> = index.execute_query(&query).await.unwrap();
1119+
assert!(results.hits[0].ranking_score_details.is_some());
1120+
Ok(())
1121+
}
1122+
10931123
#[meilisearch_test]
10941124
async fn test_phrase_search(client: Client, index: Index) -> Result<(), Error> {
10951125
setup_test_index(&client, &index).await?;

0 commit comments

Comments
 (0)