Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further reduce SDK hits when package hits have good scores. #7943

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 top package hit is 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
Loading