@@ -173,7 +173,6 @@ class InMemoryPackageIndex {
173
173
174
174
final nameMatches = textResults? .nameMatches;
175
175
List <String >? topicMatches;
176
- List <PackageHit > packageHits;
177
176
178
177
if (parsedQueryText != null ) {
179
178
final parts = parsedQueryText
@@ -187,55 +186,59 @@ class InMemoryPackageIndex {
187
186
}
188
187
}
189
188
189
+ List <IndexedPackageHit > indexedHits;
190
190
switch (query.effectiveOrder ?? SearchOrder .top) {
191
191
case SearchOrder .top:
192
192
if (textResults == null ) {
193
- packageHits = _overallOrderedHits.whereInScores (packageScores);
193
+ indexedHits = _overallOrderedHits.whereInScores (packageScores);
194
194
break ;
195
195
}
196
196
197
197
/// Adjusted score takes the overall score and transforms
198
198
/// it linearly into the [0.4-1.0] range, to allow better
199
199
/// multiplication outcomes.
200
200
packageScores.multiplyAllFromValues (_adjustedOverallScores);
201
- packageHits = _rankWithValues (packageScores);
201
+ indexedHits = _rankWithValues (packageScores);
202
202
break ;
203
203
case SearchOrder .text:
204
- packageHits = _rankWithValues (packageScores);
204
+ indexedHits = _rankWithValues (packageScores);
205
205
break ;
206
206
case SearchOrder .created:
207
- packageHits = _createdOrderedHits.whereInScores (packageScores);
207
+ indexedHits = _createdOrderedHits.whereInScores (packageScores);
208
208
break ;
209
209
case SearchOrder .updated:
210
- packageHits = _updatedOrderedHits.whereInScores (packageScores);
210
+ indexedHits = _updatedOrderedHits.whereInScores (packageScores);
211
211
break ;
212
212
case SearchOrder .popularity:
213
- packageHits = _popularityOrderedHits.whereInScores (packageScores);
213
+ indexedHits = _popularityOrderedHits.whereInScores (packageScores);
214
214
break ;
215
215
case SearchOrder .downloads:
216
- packageHits = _downloadsOrderedHits.whereInScores (packageScores);
216
+ indexedHits = _downloadsOrderedHits.whereInScores (packageScores);
217
217
break ;
218
218
case SearchOrder .like:
219
- packageHits = _likesOrderedHits.whereInScores (packageScores);
219
+ indexedHits = _likesOrderedHits.whereInScores (packageScores);
220
220
break ;
221
221
case SearchOrder .points:
222
- packageHits = _pointsOrderedHits.whereInScores (packageScores);
222
+ indexedHits = _pointsOrderedHits.whereInScores (packageScores);
223
223
break ;
224
224
}
225
225
226
226
// bound by offset and limit (or randomize items)
227
- final totalCount = packageHits.length;
228
- packageHits =
229
- boundedList (packageHits, offset: query.offset, limit: query.limit);
230
-
231
- if (textResults != null && textResults.topApiPages.isNotEmpty) {
232
- packageHits = packageHits.map ((ps) {
233
- final apiPages = textResults.topApiPages[ps.package]
227
+ final totalCount = indexedHits.length;
228
+ indexedHits =
229
+ boundedList (indexedHits, offset: query.offset, limit: query.limit);
230
+
231
+ late List <PackageHit > packageHits;
232
+ if (textResults != null && (textResults.topApiPages? .isNotEmpty ?? false )) {
233
+ packageHits = indexedHits.map ((ps) {
234
+ final apiPages = textResults.topApiPages? [ps.index]
234
235
// TODO(https://github.com/dart-lang/pub-dev/issues/7106): extract title for the page
235
236
? .map ((MapEntry <String , double > e) => ApiPageRef (path: e.key))
236
237
.toList ();
237
- return ps.change (apiPages: apiPages);
238
+ return ps.hit. change (apiPages: apiPages);
238
239
}).toList ();
240
+ } else {
241
+ packageHits = indexedHits.map ((h) => h.hit).toList ();
239
242
}
240
243
241
244
return PackageSearchResult (
@@ -311,7 +314,8 @@ class InMemoryPackageIndex {
311
314
packageScores.multiplyAllFrom (wordScore);
312
315
}
313
316
314
- final topApiPages = < String , List <MapEntry <String , double >>> {};
317
+ final topApiPages =
318
+ List <List <MapEntry <String , double >>?>.filled (_documents.length, null );
315
319
const maxApiPageCount = 2 ;
316
320
if (! checkAborted ()) {
317
321
final symbolPages = _apiSymbolIndex.searchWords (words, weight: 0.70 );
@@ -324,7 +328,7 @@ class InMemoryPackageIndex {
324
328
if (! packages.contains (doc.package)) continue ;
325
329
326
330
// skip if the previously found pages are better than the current one
327
- final pages = topApiPages. putIfAbsent ( doc.package, () => []) ;
331
+ final pages = topApiPages[ doc.index] ?? = < MapEntry < String , double > > [] ;
328
332
if (pages.length >= maxApiPageCount && pages.last.value > value) {
329
333
continue ;
330
334
}
@@ -369,7 +373,7 @@ class InMemoryPackageIndex {
369
373
return null ;
370
374
}
371
375
372
- List <PackageHit > _rankWithValues (IndexedScore <String > score) {
376
+ List <IndexedPackageHit > _rankWithValues (IndexedScore <String > score) {
373
377
final list = < IndexedPackageHit > [];
374
378
for (var i = 0 ; i < score.length; i++ ) {
375
379
final value = score.getValue (i);
@@ -383,7 +387,7 @@ class InMemoryPackageIndex {
383
387
// if two packages got the same score, order by last updated
384
388
return _compareUpdated (_documents[a.index], _documents[b.index]);
385
389
});
386
- return list.map ((h) => h.hit). toList ();
390
+ return list.toList ();
387
391
}
388
392
389
393
List <IndexedPackageHit > _rankWithComparator (
@@ -441,11 +445,11 @@ class InMemoryPackageIndex {
441
445
}
442
446
443
447
class _TextResults {
444
- final Map < String , List <MapEntry <String , double >>> topApiPages;
448
+ final List < List <MapEntry <String , double >>?> ? topApiPages;
445
449
final List <String >? nameMatches;
446
450
447
451
factory _TextResults .empty () => _TextResults (
448
- {} ,
452
+ null ,
449
453
nameMatches: null ,
450
454
);
451
455
@@ -541,8 +545,8 @@ class _PkgNameData {
541
545
}
542
546
543
547
extension on List <IndexedPackageHit > {
544
- List <PackageHit > whereInScores (IndexedScore scores) {
545
- return where ((h) => scores.isPositive (h.index)).map ((h) => h.hit). toList ();
548
+ List <IndexedPackageHit > whereInScores (IndexedScore scores) {
549
+ return where ((h) => scores.isPositive (h.index)).toList ();
546
550
}
547
551
}
548
552
0 commit comments