diff --git a/app/lib/search/mem_index.dart b/app/lib/search/mem_index.dart index 8c88c8d12..0d0228d40 100644 --- a/app/lib/search/mem_index.dart +++ b/app/lib/search/mem_index.dart @@ -72,7 +72,7 @@ class InMemoryPackageIndex { if (apiDocPages != null) { for (final page in apiDocPages) { if (page.symbols != null && page.symbols!.isNotEmpty) { - apiDocPageKeys.add(IndexedApiDocPage(i, doc.package, page)); + apiDocPageKeys.add(IndexedApiDocPage(i, page)); apiDocPageValues.add(page.symbols!.join(' ')); } } @@ -376,7 +376,8 @@ class InMemoryPackageIndex { // are multiplied. We can use a package filter that is applied after each // word to reduce the scope of the later words based on the previous results. /// However, API docs search should be filtered on the original list. - final packages = packageScores.toKeySet(); + final indexedPositiveList = packageScores.toIndexedPositiveList(); + for (final word in words) { if (includeNameMatches && _documentsByName.containsKey(word)) { nameMatches ??= {}; @@ -406,7 +407,7 @@ class InMemoryPackageIndex { if (value < 0.01) continue; final doc = symbolPages.keys[i]; - if (!packages.contains(doc.package)) continue; + if (!indexedPositiveList[doc.index]) continue; // skip if the previously found pages are better than the current one final pages = @@ -660,8 +661,7 @@ class IndexedPackageHit { class IndexedApiDocPage { final int index; - final String package; final ApiDocPage page; - IndexedApiDocPage(this.index, this.package, this.page); + IndexedApiDocPage(this.index, this.page); } diff --git a/app/lib/search/token_index.dart b/app/lib/search/token_index.dart index 2e7304b54..4f24043c0 100644 --- a/app/lib/search/token_index.dart +++ b/app/lib/search/token_index.dart @@ -250,15 +250,18 @@ class IndexedScore { } } - Set toKeySet() { - final set = {}; + /// Returns a list where each index describes whether the position in the + /// current [IndexedScore] is positive. The current instance changes are + /// not reflected in the returned list, it won't change after it was created. + List toIndexedPositiveList() { + final list = List.filled(_values.length, false); for (var i = 0; i < _values.length; i++) { final v = _values[i]; if (v > 0.0) { - set.add(_keys[i]); + list[i] = true; } } - return set; + return list; } Map top(int count, {double? minValue}) {