Skip to content

rustdoc: search result ranking fix #96879

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions src/test/rustdoc-js-std/path-ordering.js
Original file line number Diff line number Diff line change
@@ -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' },
],
};
14 changes: 14 additions & 0 deletions src/test/rustdoc-js/path-ordering.js
Original file line number Diff line number Diff line change
@@ -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' },
],
};
9 changes: 9 additions & 0 deletions src/test/rustdoc-js/path-ordering.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub mod dd {
pub struct Ccccccc;
}
pub mod aa {
pub struct Ccccccc;
}
pub mod bb {
pub struct Ccccccc;
}