diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index e0c7ed72..a3eafed3 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -840,6 +840,15 @@ search_parameter_guide_show_ranking_score_1: |- .execute() .await .unwrap(); +search_parameter_guide_show_ranking_score_details_1: |- + let results: SearchResults = client + .index("movies") + .search() + .with_query("dragon") + .with_show_ranking_score_details(true) + .execute() + .await + .unwrap(); search_parameter_guide_matching_strategy_1: |- let results: SearchResults = client .index("movies") diff --git a/src/search.rs b/src/search.rs index ec96d9d7..daae742e 100644 --- a/src/search.rs +++ b/src/search.rs @@ -51,6 +51,8 @@ pub struct SearchResult { /// The relevancy score of the match. #[serde(rename = "_rankingScore")] pub ranking_score: Option, + #[serde(rename = "_rankingScoreDetails")] + pub ranking_score_details: Option>, } #[derive(Deserialize, Debug, Clone)] @@ -322,6 +324,12 @@ pub struct SearchQuery<'a, Http: HttpClient> { #[serde(skip_serializing_if = "Option::is_none")] pub show_ranking_score: Option, + ///Adds a detailed global ranking score field to each document. + /// + /// **Default: `false`** + #[serde(skip_serializing_if = "Option::is_none")] + pub show_ranking_score_details: Option, + /// Defines the strategy on how to handle queries containing multiple words. #[serde(skip_serializing_if = "Option::is_none")] pub matching_strategy: Option, @@ -354,6 +362,7 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> { highlight_post_tag: None, show_matches_position: None, show_ranking_score: None, + show_ranking_score_details: None, matching_strategy: None, index_uid: None, } @@ -528,6 +537,15 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> { self.show_ranking_score = Some(show_ranking_score); self } + + pub fn with_show_ranking_score_details<'b>( + &'b mut self, + show_ranking_score_details: bool, + ) -> &'b mut SearchQuery<'a, Http> { + self.show_ranking_score_details = Some(show_ranking_score_details); + self + } + pub fn with_matching_strategy<'b>( &'b mut self, matching_strategy: MatchingStrategies, @@ -1090,6 +1108,21 @@ mod tests { Ok(()) } + #[meilisearch_test] + async fn test_query_show_ranking_score_details( + client: Client, + index: Index, + ) -> Result<(), Error> { + setup_test_index(&client, &index).await?; + + let mut query = SearchQuery::new(&index); + query.with_query("dolor text"); + query.with_show_ranking_score_details(true); + let results: SearchResults = index.execute_query(&query).await.unwrap(); + assert!(results.hits[0].ranking_score_details.is_some()); + Ok(()) + } + #[meilisearch_test] async fn test_phrase_search(client: Client, index: Index) -> Result<(), Error> { setup_test_index(&client, &index).await?;