Skip to content

Commit

Permalink
Merge #528
Browse files Browse the repository at this point in the history
528: Implements show ranking scores in search query r=curquiza a=massijay

# Pull Request

## Related issue
Fixes #458 

## What does this PR do?
- Implements show ranking scores in search query
- Does not implement a user friendly way to retrieve the score in the response (impossible to do without making breaking changes, see also #315, #426) users have to add the field in their classes themselves

## 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: Massimiliano Cristarella <m.cristarella@outlook.com>
Co-authored-by: Massimiliano Cristarella <massijay@outlook.com>
Co-authored-by: Clémentine U. - curqui <clementine@meilisearch.com>
  • Loading branch information
4 people committed Mar 11, 2024
2 parents a3088dc + 3ac35e0 commit ef60914
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,15 @@ search_parameter_guide_matching_strategy_1: |-
search_parameter_guide_matching_strategy_2: |-
SearchQuery params = new SearchQuery() { MatchingStrategy = "all" };
await client.Index("movies").SearchAsync<Game>("big fat liar", params);
search_parameter_guide_show_ranking_score_1: |-
var params = new SearchQuery()
{
ShowRankingScore = true
};
await client.Index("movies").SearchAsync<MovieWithRankingScore>("dragon", params);
get_proximity_precision_settings_1: |-
await client.Index("books").GetProximityPrecisionAsync();
update_proximity_precision_settings_1: |-
await client.Index("books").UpdateProximityPrecisionAsync("byAttribute");
reset_proximity_precision_settings_1: |-
await client.Index("books").ResetProximityPrecisionAsync();
await client.Index("books").ResetProximityPrecisionAsync();
6 changes: 6 additions & 0 deletions src/Meilisearch/SearchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public class SearchQuery
[JsonPropertyName("matchingStrategy")]
public string MatchingStrategy { get; set; }

/// <summary>
/// Gets or sets showRankingScore parameter. It defines wheter the global ranking score of a document (between 0 and 1) is returned or not.
/// </summary>
[JsonPropertyName("showRankingScore")]
public bool? ShowRankingScore { get; set; }

// pagination:

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions tests/Meilisearch.Tests/Movie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,14 @@ public class FormattedMovie
#pragma warning disable SA1300
public Movie _Formatted { get; set; }
}

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

public string Name { get; set; }

public string Genre { get; set; }
public double? _RankingScore { get; set; }
}
}
11 changes: 11 additions & 0 deletions tests/Meilisearch.Tests/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,5 +492,16 @@ public async Task CustomSearchWithMatchingStrategyLast()

Assert.True(movies.Hits.Count() > 1);
}

[Fact]
public async Task CustomSearchWithShowRankingScore()
{
var searchQuery = new SearchQuery()
{
ShowRankingScore = true
};
var movies = await _basicIndex.SearchAsync<MovieWithRankingScore>("iron man", searchQuery);
Assert.NotNull(movies.Hits.First()._RankingScore);
}
}
}

0 comments on commit ef60914

Please sign in to comment.