Skip to content

Commit f87d913

Browse files
committed
Auto merge of #53577 - GuillaumeGomez:rustdoc-substring-search, r=QuietMisdreavus
Search a substring instead of start of string in rustdoc search Fixes #49762. r? @QuietMisdreavus
2 parents d95f078 + e87b4b3 commit f87d913

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/librustdoc/html/static/main.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,8 @@
744744
return literalSearch === true ? false : lev_distance;
745745
}
746746

747-
function checkPath(startsWith, lastElem, ty) {
748-
if (startsWith.length === 0) {
747+
function checkPath(contains, lastElem, ty) {
748+
if (contains.length === 0) {
749749
return 0;
750750
}
751751
var ret_lev = MAX_LEV_DISTANCE + 1;
@@ -755,25 +755,25 @@
755755
path.push(ty.parent.name.toLowerCase());
756756
}
757757

758-
if (startsWith.length > path.length) {
758+
if (contains.length > path.length) {
759759
return MAX_LEV_DISTANCE + 1;
760760
}
761761
for (var i = 0; i < path.length; ++i) {
762-
if (i + startsWith.length > path.length) {
762+
if (i + contains.length > path.length) {
763763
break;
764764
}
765765
var lev_total = 0;
766766
var aborted = false;
767-
for (var x = 0; x < startsWith.length; ++x) {
768-
var lev = levenshtein(path[i + x], startsWith[x]);
767+
for (var x = 0; x < contains.length; ++x) {
768+
var lev = levenshtein(path[i + x], contains[x]);
769769
if (lev > MAX_LEV_DISTANCE) {
770770
aborted = true;
771771
break;
772772
}
773773
lev_total += lev;
774774
}
775775
if (aborted === false) {
776-
ret_lev = Math.min(ret_lev, Math.round(lev_total / startsWith.length));
776+
ret_lev = Math.min(ret_lev, Math.round(lev_total / contains.length));
777777
}
778778
}
779779
return ret_lev;
@@ -937,7 +937,7 @@
937937
}
938938
}
939939
val = paths[paths.length - 1];
940-
var startsWith = paths.slice(0, paths.length > 1 ? paths.length - 1 : 1);
940+
var contains = paths.slice(0, paths.length > 1 ? paths.length - 1 : 1);
941941

942942
for (j = 0; j < nSearchWords; ++j) {
943943
var lev_distance;
@@ -947,7 +947,7 @@
947947
}
948948
var lev_add = 0;
949949
if (paths.length > 1) {
950-
var lev = checkPath(startsWith, paths[paths.length - 1], ty);
950+
var lev = checkPath(contains, paths[paths.length - 1], ty);
951951
if (lev > MAX_LEV_DISTANCE) {
952952
continue;
953953
} else if (lev > 0) {
@@ -990,7 +990,7 @@
990990
}
991991

992992
lev += lev_add;
993-
if (lev > 0 && val.length > 3 && searchWords[j].startsWith(val)) {
993+
if (lev > 0 && val.length > 3 && searchWords[j].indexOf(val) > -1) {
994994
if (val.length < 6) {
995995
lev -= 1;
996996
} else {

src/test/rustdoc-js/substring.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// exact-check
12+
13+
const QUERY = 'waker_from';
14+
15+
const EXPECTED = {
16+
'others': [
17+
{ 'path': 'std::task', 'name': 'local_waker_from_nonlocal' },
18+
{ 'path': 'alloc::task', 'name': 'local_waker_from_nonlocal' },
19+
],
20+
};

0 commit comments

Comments
 (0)