Skip to content

Commit 60874dd

Browse files
Merge #556
556: Add parameter to show ranking score details to the search query r=curquiza a=gudmunduro # Pull Request ## Related issue Fixes #530 ## What does this PR do? - Adds the showRankingScoreDetails parameter to the search query ## 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: gudmunduro <[email protected]>
2 parents c4acbe8 + 21fd02a commit 60874dd

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,12 @@ search_parameter_guide_show_ranking_score_1: |-
755755
ShowRankingScore = true
756756
};
757757
await client.Index("movies").SearchAsync<MovieWithRankingScore>("dragon", params);
758+
search_parameter_guide_show_ranking_score_details_1: |-
759+
var params = new SearchQuery()
760+
{
761+
ShowRankingScoreDetails = true
762+
};
763+
await client.Index("movies").SearchAsync<MovieWithRankingScoreDetails>("dragon", params);
758764
get_proximity_precision_settings_1: |-
759765
await client.Index("books").GetProximityPrecisionAsync();
760766
update_proximity_precision_settings_1: |-

src/Meilisearch/SearchQuery.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public class SearchQuery
104104
[JsonPropertyName("showRankingScore")]
105105
public bool? ShowRankingScore { get; set; }
106106

107+
/// <summary>
108+
/// Gets or sets showRankingScoreDetails parameter. It defines whether details on how the ranking score was computed are returned or not.
109+
/// </summary>
110+
[JsonPropertyName("showRankingScoreDetails")]
111+
public bool? ShowRankingScoreDetails { get; set; }
112+
107113
// pagination:
108114

109115
/// <summary>

tests/Meilisearch.Tests/Movie.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System.Collections.Generic;
2+
using System.Text.Json;
3+
14
namespace Meilisearch.Tests
25
{
36
public class Movie
@@ -56,4 +59,14 @@ public class MovieWithRankingScore
5659
public string Genre { get; set; }
5760
public double? _RankingScore { get; set; }
5861
}
62+
63+
public class MovieWithRankingScoreDetails
64+
{
65+
public string Id { get; set; }
66+
67+
public string Name { get; set; }
68+
69+
public string Genre { get; set; }
70+
public IDictionary<string, JsonElement> _RankingScoreDetails { get; set; }
71+
}
5972
}

tests/Meilisearch.Tests/SearchTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,18 @@ public async Task CustomSearchWithShowRankingScore()
505505
var movies = await _basicIndex.SearchAsync<MovieWithRankingScore>("iron man", searchQuery);
506506
Assert.NotNull(movies.Hits.First()._RankingScore);
507507
}
508+
509+
[Fact]
510+
public async Task CustomSearchWithShowRankingScoreDetails()
511+
{
512+
var searchQuery = new SearchQuery()
513+
{
514+
ShowRankingScoreDetails = true
515+
};
516+
var movies = await _basicIndex.SearchAsync<MovieWithRankingScoreDetails>("iron man", searchQuery);
517+
Assert.NotEmpty(movies.Hits.First()._RankingScoreDetails);
518+
}
519+
508520
[Fact]
509521
public async Task CustomSearchProductsWithoutDistinct()
510522
{

0 commit comments

Comments
 (0)