Skip to content

Commit 33ee8c8

Browse files
authored
Remove popularity from search index. (#8446)
1 parent 3a12cb6 commit 33ee8c8

File tree

9 files changed

+23
-33
lines changed

9 files changed

+23
-33
lines changed

app/lib/search/mem_index.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class InMemoryPackageIndex {
4040
late final List<IndexedPackageHit> _overallOrderedHits;
4141
late final List<IndexedPackageHit> _createdOrderedHits;
4242
late final List<IndexedPackageHit> _updatedOrderedHits;
43-
late final List<IndexedPackageHit> _popularityOrderedHits;
4443
late final List<IndexedPackageHit> _downloadsOrderedHits;
4544
late final List<IndexedPackageHit> _likesOrderedHits;
4645
late final List<IndexedPackageHit> _pointsOrderedHits;
@@ -116,8 +115,6 @@ class InMemoryPackageIndex {
116115
score: (doc) => doc.overallScore ?? 0.0);
117116
_createdOrderedHits = _rankWithComparator(_compareCreated);
118117
_updatedOrderedHits = _rankWithComparator(_compareUpdated);
119-
_popularityOrderedHits = _rankWithComparator(_comparePopularity,
120-
score: (doc) => doc.popularityScore ?? 0);
121118
_downloadsOrderedHits = _rankWithComparator(_compareDownloads,
122119
score: (doc) => doc.downloadCount.toDouble());
123120
_likesOrderedHits = _rankWithComparator(_compareLikes,
@@ -271,9 +268,8 @@ class InMemoryPackageIndex {
271268
case SearchOrder.updated:
272269
indexedHits = _updatedOrderedHits.whereInScores(packageScores);
273270
break;
271+
// ignore: deprecated_member_use
274272
case SearchOrder.popularity:
275-
indexedHits = _popularityOrderedHits.whereInScores(packageScores);
276-
break;
277273
case SearchOrder.downloads:
278274
indexedHits = _downloadsOrderedHits.whereInScores(packageScores);
279275
break;
@@ -315,7 +311,7 @@ class InMemoryPackageIndex {
315311
/// Update the overall score both on [PackageDocument] and in the [_adjustedOverallScores] map.
316312
void _updateOverallScores() {
317313
_adjustedOverallScores = _documents.map((doc) {
318-
final downloadScore = doc.downloadScore ?? doc.popularityScore ?? 0.0;
314+
final downloadScore = doc.downloadScore ?? 0.0;
319315
final likeScore = doc.likeScore ?? 0.0;
320316
final popularity = (downloadScore + likeScore) / 2;
321317
final points = doc.grantedPoints / math.max(1, doc.maxPoints);
@@ -497,12 +493,6 @@ class InMemoryPackageIndex {
497493
return _compareUpdated(a, b);
498494
}
499495

500-
int _comparePopularity(PackageDocument a, PackageDocument b) {
501-
final x = -(a.popularityScore ?? 0.0).compareTo(b.popularityScore ?? 0.0);
502-
if (x != 0) return x;
503-
return _compareUpdated(a, b);
504-
}
505-
506496
int _compareDownloads(PackageDocument a, PackageDocument b) {
507497
final x = -a.downloadCount.compareTo(b.downloadCount);
508498
if (x != 0) return x;

app/lib/search/search_service.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ class PackageDocument {
8383
/// The normalized score between [0.0-1.0] (1.0 being the most liked package).
8484
double? likeScore;
8585

86-
/// The normalized score between [0.0-1.0] (1.0 being the most popular package).
87-
double? popularityScore;
88-
8986
final int grantedPoints;
9087
final int maxPoints;
9188

@@ -114,7 +111,6 @@ class PackageDocument {
114111
this.downloadScore,
115112
int? likeCount,
116113
this.likeScore,
117-
this.popularityScore,
118114
int? grantedPoints,
119115
int? maxPoints,
120116
this.dependencies = const {},

app/lib/search/search_service.g.dart

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/lib/search/top_packages.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TopPackages {
2929
query: PackageTags.isFlutterFavorite,
3030
);
3131
final _mostPopular =
32-
_cachedValue('top-packages-most-popular', order: SearchOrder.popularity);
32+
_cachedValue('top-packages-most-popular', order: SearchOrder.downloads);
3333
final _topDart = _cachedValue('top-packages-top-dart', query: SdkTag.sdkDart);
3434
final _topFlutter =
3535
_cachedValue('top-packages-top-flutter', query: SdkTag.sdkFlutter);

app/lib/shared/urls.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ String searchUrl({
219219
}
220220

221221
String listingByPopularity() =>
222-
SearchForm(order: SearchOrder.popularity).toSearchLink();
222+
SearchForm(order: SearchOrder.downloads).toSearchLink();
223223

224224
String dartSdkMainUrl(String version) {
225225
final isDev = version.contains('dev');

app/test/frontend/golden/landing_page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ <h3>oxygen</h3>
176176
</div>
177177
</div>
178178
<div class="home-block-view-all">
179-
<a class="home-block-view-all-link" href="/packages?sort=popularity" rel="nofollow" title="Search popular packages" data-ga-click-event="landing-most-popular-view-all">View all</a>
179+
<a class="home-block-view-all-link" href="/packages?sort=downloads" rel="nofollow" title="Search popular packages" data-ga-click-event="landing-most-popular-view-all">View all</a>
180180
</div>
181181
</div>
182182
</div>

app/test/search/mem_index_test.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ void main() {
3434
'runtime:web'
3535
],
3636
likeCount: 10,
37-
popularityScore: 0.7,
3837
downloadScore: 0.7,
38+
downloadCount: 70,
3939
grantedPoints: 110,
4040
maxPoints: 110,
4141
dependencies: {'async': 'direct', 'test': 'dev', 'foo': 'transitive'},
@@ -64,8 +64,8 @@ The delegating wrapper classes allow users to easily add functionality on top of
6464
grantedPoints: 10,
6565
maxPoints: 110,
6666
dependencies: {'test': 'dev'},
67-
popularityScore: 0.8,
6867
downloadScore: 0.8,
68+
downloadCount: 80,
6969
),
7070
PackageDocument(
7171
package: 'chrome_net',
@@ -81,6 +81,7 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
8181
grantedPoints: 0,
8282
maxPoints: 110,
8383
downloadScore: 0.0,
84+
downloadCount: 0,
8485
),
8586
];
8687
lastPackageUpdated =
@@ -280,16 +281,16 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
280281
});
281282
});
282283

283-
test('order by popularity', () async {
284+
test('order by downloads', () async {
284285
final PackageSearchResult result =
285-
index.search(ServiceSearchQuery.parse(order: SearchOrder.popularity));
286+
index.search(ServiceSearchQuery.parse(order: SearchOrder.downloads));
286287
expect(json.decode(json.encode(result)), {
287288
'timestamp': isNotNull,
288289
'totalCount': 3,
289290
'sdkLibraryHits': [],
290291
'packageHits': [
291-
{'package': 'async', 'score': 0.8},
292-
{'package': 'http', 'score': 0.7},
292+
{'package': 'async', 'score': 80},
293+
{'package': 'http', 'score': 70},
293294
{'package': 'chrome_net', 'score': 0.0},
294295
],
295296
});

app/test/search/result_combiner_test.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ void main() {
2323
readme: 'Many useful string methods like substring.',
2424
grantedPoints: 110,
2525
maxPoints: 110,
26-
popularityScore: 0.4,
26+
downloadScore: 0.4,
27+
downloadCount: 4,
2728
),
2829
],
2930
);
@@ -78,13 +79,13 @@ void main() {
7879

7980
test('non-text ranking', () async {
8081
final results = combiner
81-
.search(ServiceSearchQuery.parse(order: SearchOrder.popularity));
82+
.search(ServiceSearchQuery.parse(order: SearchOrder.downloads));
8283
expect(json.decode(json.encode(results.toJson())), {
8384
'timestamp': isNotNull,
8485
'totalCount': 1,
8586
'sdkLibraryHits': [],
8687
'packageHits': [
87-
{'package': 'stringutils', 'score': 0.4},
88+
{'package': 'stringutils', 'score': 4},
8889
],
8990
});
9091
});
@@ -97,7 +98,7 @@ void main() {
9798
'totalCount': 1,
9899
'sdkLibraryHits': [],
99100
'packageHits': [
100-
{'package': 'stringutils', 'score': closeTo(1.0, 0.01)},
101+
{'package': 'stringutils', 'score': closeTo(0.85, 0.01)},
101102
],
102103
});
103104
});
@@ -124,7 +125,7 @@ void main() {
124125
},
125126
],
126127
'packageHits': [
127-
{'package': 'stringutils', 'score': closeTo(0.73, 0.01)}
128+
{'package': 'stringutils', 'score': closeTo(0.67, 0.01)}
128129
],
129130
});
130131
});

pkg/_pub_shared/lib/search/search_form.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int extractPageFromUrlParameters(Map<String, String> queryParameters) {
3535

3636
/// How search results should be ordered.
3737
enum SearchOrder {
38-
/// Search score should be a weighted value of [text], [popularity], [points]
38+
/// Search score should be a weighted value of [text], [downloads], [points]
3939
/// and [like], ordered decreasing.
4040
top,
4141

@@ -50,6 +50,10 @@ enum SearchOrder {
5050
updated,
5151

5252
/// Search order should be in decreasing popularity score.
53+
/// WARNING: The value shouldn't be used anymore.
54+
///
55+
/// TODO: remove in a future release.
56+
@Deprecated('Popularity is no longer used.')
5357
popularity,
5458

5559
/// Search order should be in decreasing download counts.

0 commit comments

Comments
 (0)