Skip to content

Commit

Permalink
Merge #556
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
meili-bors[bot] and gudmunduro authored Aug 6, 2024
2 parents c4acbe8 + 21fd02a commit 60874dd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,12 @@ search_parameter_guide_show_ranking_score_1: |-
ShowRankingScore = true
};
await client.Index("movies").SearchAsync<MovieWithRankingScore>("dragon", params);
search_parameter_guide_show_ranking_score_details_1: |-
var params = new SearchQuery()
{
ShowRankingScoreDetails = true
};
await client.Index("movies").SearchAsync<MovieWithRankingScoreDetails>("dragon", params);
get_proximity_precision_settings_1: |-
await client.Index("books").GetProximityPrecisionAsync();
update_proximity_precision_settings_1: |-
Expand Down
6 changes: 6 additions & 0 deletions src/Meilisearch/SearchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public class SearchQuery
[JsonPropertyName("showRankingScore")]
public bool? ShowRankingScore { get; set; }

/// <summary>
/// Gets or sets showRankingScoreDetails parameter. It defines whether details on how the ranking score was computed are returned or not.
/// </summary>
[JsonPropertyName("showRankingScoreDetails")]
public bool? ShowRankingScoreDetails { get; set; }

// pagination:

/// <summary>
Expand Down
13 changes: 13 additions & 0 deletions tests/Meilisearch.Tests/Movie.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System.Collections.Generic;
using System.Text.Json;

namespace Meilisearch.Tests
{
public class Movie
Expand Down Expand Up @@ -56,4 +59,14 @@ public class MovieWithRankingScore
public string Genre { get; set; }
public double? _RankingScore { get; set; }
}

public class MovieWithRankingScoreDetails
{
public string Id { get; set; }

public string Name { get; set; }

public string Genre { get; set; }
public IDictionary<string, JsonElement> _RankingScoreDetails { get; set; }
}
}
12 changes: 12 additions & 0 deletions tests/Meilisearch.Tests/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,18 @@ public async Task CustomSearchWithShowRankingScore()
var movies = await _basicIndex.SearchAsync<MovieWithRankingScore>("iron man", searchQuery);
Assert.NotNull(movies.Hits.First()._RankingScore);
}

[Fact]
public async Task CustomSearchWithShowRankingScoreDetails()
{
var searchQuery = new SearchQuery()
{
ShowRankingScoreDetails = true
};
var movies = await _basicIndex.SearchAsync<MovieWithRankingScoreDetails>("iron man", searchQuery);
Assert.NotEmpty(movies.Hits.First()._RankingScoreDetails);
}

[Fact]
public async Task CustomSearchProductsWithoutDistinct()
{
Expand Down

0 comments on commit 60874dd

Please sign in to comment.