mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-10-11 14:16:31 +00:00
Fix ranking score bug when sort is present
- Fix global_score function to properly handle semantic scores and ranking scores - Prioritize semantic scores (vector/embedding) when available, fall back to ranking scores - Exclude sort and geo sort details from relevance scoring - Use Rank::global_score to properly merge ranking scores - Add test case with insta snapshots to reproduce and verify the fix - When sorting is present, ranking scores now properly reflect search relevance - Previously all ranking scores were 1.0 when sort was present, now they show actual relevance scores
This commit is contained in:
@@ -67,14 +67,22 @@ impl ScoreDetails {
|
||||
}
|
||||
|
||||
pub fn global_score<'a>(details: impl Iterator<Item = &'a Self> + 'a) -> f64 {
|
||||
Self::score_values(details)
|
||||
.find_map(|x| {
|
||||
let ScoreValue::Score(score) = x else {
|
||||
return None;
|
||||
};
|
||||
Some(score)
|
||||
})
|
||||
.unwrap_or(1.0f64)
|
||||
// Filter out only the ranking scores (Rank values) and exclude sort/geo sort
|
||||
let mut semantic_score = None;
|
||||
let ranking_ranks = details.filter_map(|detail| match detail.rank_or_value() {
|
||||
RankOrValue::Rank(rank) => Some(rank),
|
||||
RankOrValue::Score(score) => {
|
||||
semantic_score = Some(score);
|
||||
None
|
||||
}
|
||||
RankOrValue::Sort(_) => None,
|
||||
RankOrValue::GeoSort(_) => None,
|
||||
});
|
||||
|
||||
let ranking_score = Rank::global_score(ranking_ranks);
|
||||
|
||||
// If we have semantic score, use it, otherwise use ranking score
|
||||
semantic_score.unwrap_or(ranking_score)
|
||||
}
|
||||
|
||||
pub fn score_values<'a>(
|
||||
|
Reference in New Issue
Block a user