From f8bf56c11f1b9c80e5b572d3887af0c475fc6811 Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Thu, 15 Aug 2024 12:45:49 +0200 Subject: [PATCH] Further reduce SDK hits when package hits have good scores. --- app/lib/search/result_combiner.dart | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/lib/search/result_combiner.dart b/app/lib/search/result_combiner.dart index ca716e38c6..501fccd20c 100644 --- a/app/lib/search/result_combiner.dart +++ b/app/lib/search/result_combiner.dart @@ -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)); }