diff --git a/app/lib/search/mem_index.dart b/app/lib/search/mem_index.dart index bce0de1099..687b474242 100644 --- a/app/lib/search/mem_index.dart +++ b/app/lib/search/mem_index.dart @@ -313,9 +313,15 @@ class InMemoryPackageIndex { _adjustedOverallScores = _documents.map((doc) { final downloadScore = doc.downloadScore ?? 0.0; final likeScore = doc.likeScore ?? 0.0; - final combinedScore = (downloadScore + likeScore) / 2; - final points = doc.grantedPoints / math.max(1, doc.maxPoints); - final overall = combinedScore * 0.5 + points * 0.5; + final popularityScore = (downloadScore + likeScore) / 2; + + // prevent division by zero in case maxPoints is zero + final pointRatio = doc.grantedPoints / math.max(1, doc.maxPoints); + // force value between 0.0 and 1.0 in case we have bad points + // using square root to lower the differences between higher values + final pointScore = math.sqrt(math.max(0.0, math.min(1.0, pointRatio))); + + final overall = popularityScore * 0.5 + pointScore * 0.5; doc.overallScore = overall; // adding a base score prevents later multiplication with zero return 0.4 + 0.6 * overall; diff --git a/app/test/search/mem_index_test.dart b/app/test/search/mem_index_test.dart index 5fdcb04e63..a7e322ae42 100644 --- a/app/test/search/mem_index_test.dart +++ b/app/test/search/mem_index_test.dart @@ -98,7 +98,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure 'nameMatches': ['async'], 'sdkLibraryHits': [], 'packageHits': [ - {'package': 'async', 'score': closeTo(0.65, 0.01)}, + {'package': 'async', 'score': closeTo(0.71, 0.01)}, ], }); }); @@ -143,8 +143,8 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure 'totalCount': 2, 'sdkLibraryHits': [], 'packageHits': [ + {'package': 'async', 'score': closeTo(0.71, 0.01)}, {'package': 'http', 'score': closeTo(0.69, 0.01)}, - {'package': 'async', 'score': closeTo(0.65, 0.01)}, ], }); }); @@ -157,7 +157,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure 'totalCount': 1, 'sdkLibraryHits': [], 'packageHits': [ - {'package': 'async', 'score': closeTo(0.34, 0.01)}, + {'package': 'async', 'score': closeTo(0.37, 0.01)}, ], }); }); @@ -183,7 +183,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure 'totalCount': 1, 'sdkLibraryHits': [], 'packageHits': [ - {'package': 'async', 'score': closeTo(0.24, 0.01)}, + {'package': 'async', 'score': closeTo(0.26, 0.01)}, ], }); }); @@ -335,7 +335,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure 'sdkLibraryHits': [], 'packageHits': [ {'package': 'http', 'score': closeTo(0.92, 0.01)}, - {'package': 'async', 'score': closeTo(0.41, 0.01)}, + {'package': 'async', 'score': closeTo(0.52, 0.01)}, ], }); @@ -422,7 +422,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure 'totalCount': 1, 'sdkLibraryHits': [], 'packageHits': [ - {'package': 'async', 'score': closeTo(0.41, 0.01)}, + {'package': 'async', 'score': closeTo(0.52, 0.01)}, ], });