Rollup merge of #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)
This commit is contained in:
Yuki Okushi 2022-05-11 00:09:35 +09:00 committed by GitHub
commit d34915f691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 1 deletions

View File

@ -1323,7 +1323,6 @@ window.initSearch = rawSearchIndex => {
}
}
lev = levenshtein(searchWord, elem.pathLast);
lev += lev_add;
if (lev > 0 && elem.pathLast.length > 2 && searchWord.indexOf(elem.pathLast) > -1)
{
if (elem.pathLast.length < 6) {
@ -1332,6 +1331,7 @@ window.initSearch = rawSearchIndex => {
lev = 0;
}
}
lev += lev_add;
if (lev > MAX_LEV_DISTANCE) {
return;
} else if (index !== -1 && elem.fullPath.length < 2) {

View File

@ -0,0 +1,12 @@
const QUERY = 'hashset::insert';
const EXPECTED = {
'others': [
// ensure hashset::insert comes first
{ 'path': 'std::collections::hash_set::HashSet', 'name': 'insert' },
{ 'path': 'std::collections::hash_set::HashSet', 'name': 'get_or_insert' },
{ 'path': 'std::collections::hash_set::HashSet', 'name': 'get_or_insert_with' },
{ 'path': 'std::collections::hash_set::HashSet', 'name': 'get_or_insert_owned' },
{ 'path': 'std::collections::hash_map::HashMap', 'name': 'insert' },
],
};

View File

@ -0,0 +1,14 @@
// exact-check
const QUERY = 'b::ccccccc';
const EXPECTED = {
'others': [
// `ccccccc` is an exact match for all three of these.
// However `b` is a closer match for `bb` than for any
// of the others, so it ought to go first.
{ 'path': 'path_ordering::bb', 'name': 'Ccccccc' },
{ 'path': 'path_ordering::aa', 'name': 'Ccccccc' },
{ 'path': 'path_ordering::dd', 'name': 'Ccccccc' },
],
};

View File

@ -0,0 +1,9 @@
pub mod dd {
pub struct Ccccccc;
}
pub mod aa {
pub struct Ccccccc;
}
pub mod bb {
pub struct Ccccccc;
}