@@ -43,6 +43,7 @@ class InMemoryPackageIndex {
4343 late final List <IndexedPackageHit > _downloadsOrderedHits;
4444 late final List <IndexedPackageHit > _likesOrderedHits;
4545 late final List <IndexedPackageHit > _pointsOrderedHits;
46+ late final List <IndexedPackageHit > _trendingOrderedHits;
4647
4748 // Contains all of the topics the index had seen so far.
4849 // TODO: consider moving this into a separate index
@@ -121,6 +122,8 @@ class InMemoryPackageIndex {
121122 score: (doc) => doc.likeCount.toDouble ());
122123 _pointsOrderedHits = _rankWithComparator (_comparePoints,
123124 score: (doc) => doc.grantedPoints.toDouble ());
125+ _trendingOrderedHits = _rankWithComparator (_compareTrending,
126+ score: (doc) => doc.trendScore.toDouble ());
124127 }
125128
126129 IndexInfo indexInfo () {
@@ -289,6 +292,9 @@ class InMemoryPackageIndex {
289292 case SearchOrder .points:
290293 indexedHits = _pointsOrderedHits.whereInScores (packageScores);
291294 break ;
295+ case SearchOrder .trending:
296+ indexedHits = _trendingOrderedHits.whereInScores (packageScores);
297+ break ;
292298 }
293299
294300 // bound by offset and limit (or randomize items)
@@ -532,6 +538,12 @@ class InMemoryPackageIndex {
532538 if (x != 0 ) return x;
533539 return _compareUpdated (a, b);
534540 }
541+
542+ int _compareTrending (PackageDocument a, PackageDocument b) {
543+ final x = - a.trendScore.compareTo (b.trendScore);
544+ if (x != 0 ) return x;
545+ return _compareUpdated (a, b);
546+ }
535547}
536548
537549class _TextResults {
0 commit comments