Skip to content

Commit 62b9db2

Browse files
authored
Earlier cutoff in package name index. (#8290)
1 parent 362413e commit 62b9db2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

app/lib/search/mem_index.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,23 @@ class PackageNameIndex {
520520
continue;
521521
}
522522
var matched = 0;
523+
var unmatched = 0;
524+
final acceptThreshold = parts.length ~/ 2;
525+
final rejectThreshold = parts.length - acceptThreshold;
523526
for (final part in parts) {
524527
if (entry.trigrams.contains(part)) {
525528
matched++;
529+
} else {
530+
unmatched++;
531+
if (unmatched > rejectThreshold) {
532+
// we have no chance to accept this hit
533+
break;
534+
}
526535
}
527536
}
528537

529-
// making sure that match score is minimum 0.5
530-
if (matched > 0) {
538+
if (matched >= acceptThreshold) {
539+
// making sure that match score is minimum 0.5
531540
final v = matched / parts.length;
532541
if (v >= 0.5) {
533542
score.setValue(i, v);

0 commit comments

Comments
 (0)