Skip to content

Commit d3d6ff7

Browse files
authored
Use square root of points for normalized score. (#8572)
1 parent 7b3baf8 commit d3d6ff7

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

app/lib/search/mem_index.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,15 @@ class InMemoryPackageIndex {
313313
_adjustedOverallScores = _documents.map((doc) {
314314
final downloadScore = doc.downloadScore ?? 0.0;
315315
final likeScore = doc.likeScore ?? 0.0;
316-
final combinedScore = (downloadScore + likeScore) / 2;
317-
final points = doc.grantedPoints / math.max(1, doc.maxPoints);
318-
final overall = combinedScore * 0.5 + points * 0.5;
316+
final popularityScore = (downloadScore + likeScore) / 2;
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+
324+
final overall = popularityScore * 0.5 + pointScore * 0.5;
319325
doc.overallScore = overall;
320326
// adding a base score prevents later multiplication with zero
321327
return 0.4 + 0.6 * overall;

app/test/search/mem_index_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
9898
'nameMatches': ['async'],
9999
'sdkLibraryHits': [],
100100
'packageHits': [
101-
{'package': 'async', 'score': closeTo(0.65, 0.01)},
101+
{'package': 'async', 'score': closeTo(0.71, 0.01)},
102102
],
103103
});
104104
});
@@ -143,8 +143,8 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
143143
'totalCount': 2,
144144
'sdkLibraryHits': [],
145145
'packageHits': [
146+
{'package': 'async', 'score': closeTo(0.71, 0.01)},
146147
{'package': 'http', 'score': closeTo(0.69, 0.01)},
147-
{'package': 'async', 'score': closeTo(0.65, 0.01)},
148148
],
149149
});
150150
});
@@ -157,7 +157,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
157157
'totalCount': 1,
158158
'sdkLibraryHits': [],
159159
'packageHits': [
160-
{'package': 'async', 'score': closeTo(0.34, 0.01)},
160+
{'package': 'async', 'score': closeTo(0.37, 0.01)},
161161
],
162162
});
163163
});
@@ -183,7 +183,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
183183
'totalCount': 1,
184184
'sdkLibraryHits': [],
185185
'packageHits': [
186-
{'package': 'async', 'score': closeTo(0.24, 0.01)},
186+
{'package': 'async', 'score': closeTo(0.26, 0.01)},
187187
],
188188
});
189189
});
@@ -335,7 +335,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
335335
'sdkLibraryHits': [],
336336
'packageHits': [
337337
{'package': 'http', 'score': closeTo(0.92, 0.01)},
338-
{'package': 'async', 'score': closeTo(0.41, 0.01)},
338+
{'package': 'async', 'score': closeTo(0.52, 0.01)},
339339
],
340340
});
341341

@@ -422,7 +422,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
422422
'totalCount': 1,
423423
'sdkLibraryHits': [],
424424
'packageHits': [
425-
{'package': 'async', 'score': closeTo(0.41, 0.01)},
425+
{'package': 'async', 'score': closeTo(0.52, 0.01)},
426426
],
427427
});
428428

0 commit comments

Comments
 (0)