Skip to content

Commit 6351ebb

Browse files
make doc search more relevant
1 parent b4f3232 commit 6351ebb

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/librustdoc/html/static/main.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,9 @@
681681
}
682682

683683
function checkPath(startsWith, lastElem, ty) {
684+
if (startsWith.length === 0) {
685+
return 0;
686+
}
684687
var ret_lev = MAX_LEV_DISTANCE + 1;
685688
var path = ty.path.split("::");
686689

@@ -706,18 +709,7 @@
706709
lev_total += lev;
707710
}
708711
if (aborted === false) {
709-
var extra = MAX_LEV_DISTANCE + 1;
710-
if (i + startsWith.length < path.length) {
711-
extra = levenshtein(path[i + startsWith.length], lastElem);
712-
}
713-
if (extra > MAX_LEV_DISTANCE) {
714-
extra = levenshtein(ty.name, lastElem);
715-
}
716-
if (extra < MAX_LEV_DISTANCE + 1) {
717-
lev_total += extra;
718-
ret_lev = Math.min(ret_lev,
719-
Math.round(lev_total / (startsWith.length + 1)));
720-
}
712+
ret_lev = Math.min(ret_lev, Math.round(lev_total / startsWith.length));
721713
}
722714
}
723715
return ret_lev;
@@ -934,6 +926,9 @@
934926
}
935927

936928
lev += lev_add;
929+
if (searchWords[j].startsWith(val)) {
930+
lev -= 1;
931+
}
937932
if (in_args <= MAX_LEV_DISTANCE) {
938933
if (results_in_args[fullId] === undefined) {
939934
results_in_args[fullId] = {

0 commit comments

Comments
 (0)