Skip to content

Commit 90afef8

Browse files
committed
Sortcut when the query text is 1:1 package name.
1 parent 1004d37 commit 90afef8

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

app/lib/search/mem_index.dart

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -230,20 +230,26 @@ class InMemoryPackageIndex {
230230

231231
String? bestNameMatch;
232232
if (parsedQueryText != null) {
233-
final matches = _packageNameIndex.lookupMatchingNames(parsedQueryText);
234-
if (matches != null && matches.isNotEmpty) {
235-
bestNameMatch = matches.length == 1
236-
? matches.single
237-
:
238-
// Note: to keep it simple, we select the most downloaded one from competing matches.
239-
matches.reduce((a, b) {
240-
if (_documentsByName[a]!.downloadCount >
241-
_documentsByName[b]!.downloadCount) {
242-
return a;
243-
} else {
244-
return b;
245-
}
246-
});
233+
// exact package name
234+
if (_documentsByName.containsKey(parsedQueryText)) {
235+
bestNameMatch = parsedQueryText;
236+
} else {
237+
// reduced package name match
238+
final matches = _packageNameIndex.lookupMatchingNames(parsedQueryText);
239+
if (matches != null && matches.isNotEmpty) {
240+
bestNameMatch = matches.length == 1
241+
? matches.single
242+
:
243+
// Note: to keep it simple, we select the most downloaded one from competing matches.
244+
matches.reduce((a, b) {
245+
if (_documentsByName[a]!.downloadCount >
246+
_documentsByName[b]!.downloadCount) {
247+
return a;
248+
} else {
249+
return b;
250+
}
251+
});
252+
}
247253
}
248254
}
249255

0 commit comments

Comments
 (0)