Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/lib/search/mem_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(' '));
}
}
Expand Down Expand Up @@ -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 ??= <String>{};
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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);
}
11 changes: 7 additions & 4 deletions app/lib/search/token_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,18 @@ class IndexedScore<K> {
}
}

Set<K> toKeySet() {
final set = <K>{};
/// 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<bool> 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<K, double> top(int count, {double? minValue}) {
Expand Down
Loading