@@ -160,22 +160,15 @@ class InMemoryPackageIndex {
160160 packageScores.removeWhere (
161161 (i, _) => now.difference (_documents[i].updated) > updatedDuration);
162162 }
163- final packages = packageScores.toKeySet ();
164163
165164 // do text matching
166165 final parsedQueryText = query.parsedQuery.text;
167166 final textResults = _searchText (
168- packages ,
167+ packageScores ,
169168 parsedQueryText,
170169 includeNameMatches: (query.offset ?? 0 ) == 0 ,
171170 );
172171
173- // filter packages that doesn't match text query
174- if (textResults != null ) {
175- final keys = textResults.pkgScore.keys.toSet ();
176- packages.removeWhere ((x) => ! keys.contains (x));
177- }
178-
179172 final nameMatches = textResults? .nameMatches;
180173 List <String >? topicMatches;
181174 List <PackageHit > packageHits;
@@ -192,6 +185,7 @@ class InMemoryPackageIndex {
192185 }
193186 }
194187
188+ final packages = packageScores.toKeySet ();
195189 switch (query.effectiveOrder ?? SearchOrder .top) {
196190 case SearchOrder .top:
197191 if (textResults == null ) {
@@ -270,7 +264,7 @@ class InMemoryPackageIndex {
270264 }
271265
272266 _TextResults ? _searchText (
273- Set < String > packages ,
267+ IndexedScore packageScores ,
274268 String ? text, {
275269 required bool includeNameMatches,
276270 }) {
@@ -301,31 +295,22 @@ class InMemoryPackageIndex {
301295 // Multiple words are scored separately, and then the individual scores
302296 // are multiplied. We can use a package filter that is applied after each
303297 // word to reduce the scope of the later words based on the previous results.
304- // We cannot update the main `packages` variable yet, as the dartdoc API
305- // symbols are added on top of the core results, and `packages` is used
306- // there too.
307- final coreScores = IndexedScore (_packageNameIndex._packageNames);
308- for (var i = 0 ; i < _documents.length; i++ ) {
309- if (packages.contains (_documents[i].package)) {
310- coreScores.setValue (i, 1.0 );
311- }
312- }
298+ /// However, API docs search should be filtered on the original list.
299+ final packages = packageScores.toKeySet ();
313300 for (final word in words) {
314301 if (includeNameMatches && _documentsByName.containsKey (word)) {
315302 nameMatches ?? = < String > {};
316303 nameMatches.add (word);
317304 }
318305
319306 final wordScore =
320- _packageNameIndex.searchWord (word, filterOnNonZeros: coreScores);
321- _descrIndex.searchAndAccumulate (word,
322- weight: 0.90 .toDouble (), score: wordScore);
323- _readmeIndex.searchAndAccumulate (word,
324- weight: 0.75 .toDouble (), score: wordScore);
325- coreScores.multiplyAllFrom (wordScore);
307+ _packageNameIndex.searchWord (word, filterOnNonZeros: packageScores);
308+ _descrIndex.searchAndAccumulate (word, weight: 0.90 , score: wordScore);
309+ _readmeIndex.searchAndAccumulate (word, weight: 0.75 , score: wordScore);
310+ packageScores.multiplyAllFrom (wordScore);
326311 }
327312
328- final core = coreScores .toScore ();
313+ final core = packageScores .toScore ();
329314
330315 var symbolPages = Score .empty;
331316 if (! checkAborted ()) {
@@ -361,7 +346,6 @@ class InMemoryPackageIndex {
361346
362347 final apiPkgScore = Score (apiPackages);
363348 var score = Score .max ([core, apiPkgScore])
364- .project (packages)
365349 .removeLowValues (fraction: 0.2 , minValue: 0.01 );
366350
367351 // filter results based on exact phrases
0 commit comments