Skip to content

Commit 2ea5731

Browse files
committed
different normalization + comments
1 parent 4891b78 commit 2ea5731

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

app/lib/search/mem_index.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,13 @@ class InMemoryPackageIndex {
314314
final downloadScore = doc.downloadScore ?? 0.0;
315315
final likeScore = doc.likeScore ?? 0.0;
316316
final popularityScore = (downloadScore + likeScore) / 2;
317-
final pointScore =
318-
math.sqrt(doc.grantedPoints / math.max(1, doc.maxPoints));
317+
318+
// prevent division by zero in case maxPoints is zero
319+
final pointRatio = doc.grantedPoints / math.max(1, doc.maxPoints);
320+
// force value between 0.0 and 1.0 in case we have bad points
321+
// using square root to lower the differences between higher values
322+
final pointScore = math.sqrt(math.max(0.0, math.min(1.0, pointRatio)));
323+
319324
final overall = popularityScore * 0.5 + pointScore * 0.5;
320325
doc.overallScore = overall;
321326
// adding a base score prevents later multiplication with zero

0 commit comments

Comments
 (0)