Skip to content

Commit

Permalink
Further reduce SDK hits when package hits have good scores.
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos committed Aug 15, 2024
1 parent b95d3e4 commit f8bf56c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions app/lib/search/result_combiner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ class SearchResultCombiner {
...?flutterSdkMemIndex?.search(query.query!, limit: 2),
];
if (sdkLibraryHits.isNotEmpty) {
// Do not display low SDK scores if the average package hits are more relevant on the page.
// Do not display low SDK scores if the package hits are more relevant on the page.
//
// Note: we used to pick the lowest item's score for this threshold, but it was not ideal,
// because promoted hit of the exact package name match may have very low score.
final primaryHitsScores =
primaryResult.packageHits.map((a) => a.score ?? 0.0).toList();
final primaryHitsAvgScore =
primaryHitsScores.isEmpty ? 0.0 : primaryHitsScores.average;
if (primaryHitsAvgScore > 0) {
sdkLibraryHits.removeWhere((hit) => hit.score < primaryHitsAvgScore);
final primaryHitsTopScore =
primaryResult.packageHits.map((a) => a.score ?? 0.0).maxOrNull ?? 0.0;
if (primaryHitsTopScore > 0) {
sdkLibraryHits.removeWhere((hit) => hit.score < primaryHitsTopScore);
}
sdkLibraryHits.sort((a, b) => -a.score.compareTo(b.score));
}
Expand Down

0 comments on commit f8bf56c

Please sign in to comment.