Skip to content

Commit cfbcebe

Browse files
meili-bors[bot]NoodleSamaChanirevoire
authored
Merge #592
592: Added score ranking details r=irevoire a=NoodleSamaChan # Pull Request Hello : ) I wasn't sure if I had to deserialise the ranking score details object in the search result so I kept it as a json value, don't hesitate to let me know if you need me to change that. Cheers ## Related issue fixes #556 ## What does this PR do? fixes #556 ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: NoodleSamaChan <[email protected]> Co-authored-by: Tamo <[email protected]>
2 parents ea99fca + 13bba10 commit cfbcebe

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,15 @@ search_parameter_guide_show_ranking_score_1: |-
840840
.execute()
841841
.await
842842
.unwrap();
843+
search_parameter_guide_show_ranking_score_details_1: |-
844+
let results: SearchResults<Movie> = client
845+
.index("movies")
846+
.search()
847+
.with_query("dragon")
848+
.with_show_ranking_score_details(true)
849+
.execute()
850+
.await
851+
.unwrap();
843852
search_parameter_guide_matching_strategy_1: |-
844853
let results: SearchResults<Movie> = client
845854
.index("movies")

src/search.rs

Lines changed: 33 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,21 @@ mod tests {
10901108
Ok(())
10911109
}
10921110

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

0 commit comments

Comments
 (0)