Skip to content

Commit d34915f

Browse files
authored
Rollup merge of rust-lang#96879 - notriddle:notriddle/search-ranking, r=GuillaumeGomez
rustdoc: search result ranking fix # Before ![image](https://user-images.githubusercontent.com/1593513/167477286-91049761-67f9-4a73-8fb7-09dbb19ca76c.png) # After ![image](https://user-images.githubusercontent.com/1593513/167477345-6733bc0f-4bb2-4625-9f7f-094031e36414.png)
2 parents 7274447 + a9a90d4 commit d34915f

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-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) {
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const QUERY = 'hashset::insert';
2+
3+
const EXPECTED = {
4+
'others': [
5+
// ensure hashset::insert comes first
6+
{ 'path': 'std::collections::hash_set::HashSet', 'name': 'insert' },
7+
{ 'path': 'std::collections::hash_set::HashSet', 'name': 'get_or_insert' },
8+
{ 'path': 'std::collections::hash_set::HashSet', 'name': 'get_or_insert_with' },
9+
{ 'path': 'std::collections::hash_set::HashSet', 'name': 'get_or_insert_owned' },
10+
{ 'path': 'std::collections::hash_map::HashMap', 'name': 'insert' },
11+
],
12+
};

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)