Skip to content

Commit 360d6e4

Browse files
committed
rustdoc: search result ranking fix
1 parent 0e345b7 commit 360d6e4

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/librustdoc/html/static/js/search.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,6 @@ window.initSearch = rawSearchIndex => {
13231323
}
13241324
}
13251325
lev = levenshtein(searchWord, elem.pathLast);
1326-
lev += lev_add;
13271326
if (lev > 0 && elem.pathLast.length > 2 && searchWord.indexOf(elem.pathLast) > -1)
13281327
{
13291328
if (elem.pathLast.length < 6) {
@@ -1332,6 +1331,7 @@ window.initSearch = rawSearchIndex => {
13321331
lev = 0;
13331332
}
13341333
}
1334+
lev += lev_add;
13351335
if (lev > MAX_LEV_DISTANCE) {
13361336
return;
13371337
} else if (index !== -1 && elem.fullPath.length < 2) {

src/test/rustdoc-js/path-ordering.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// exact-check
2+
3+
const QUERY = 'b::ccccccc';
4+
5+
const EXPECTED = {
6+
'others': [
7+
// `ccccccc` is an exact match for all three of these.
8+
// However `b` is a closer match for `bb` than for any
9+
// of the others, so it ought to go first.
10+
{ 'path': 'path_ordering::bb', 'name': 'Ccccccc' },
11+
{ 'path': 'path_ordering::aa', 'name': 'Ccccccc' },
12+
{ 'path': 'path_ordering::dd', 'name': 'Ccccccc' },
13+
],
14+
};

src/test/rustdoc-js/path-ordering.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub mod dd {
2+
pub struct Ccccccc;
3+
}
4+
pub mod aa {
5+
pub struct Ccccccc;
6+
}
7+
pub mod bb {
8+
pub struct Ccccccc;
9+
}

0 commit comments

Comments
 (0)