Rollup merge of #145100 - GuillaumeGomez:rank-doc-alias-lower, r=lolbinarycat

Rank doc aliases lower than equivalently matched items

Follow-up of https://github.com/rust-lang/rust/pull/143988.

cc `@lolbinarycat`
This commit is contained in:
Stuart Cook 2025-08-09 13:58:52 +10:00 committed by GitHub
commit cd1e82ac72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 54 additions and 0 deletions

View file

@ -3365,6 +3365,13 @@ class DocSearch {
return a - b;
}
// sort doc alias items later
a = Number(aaa.item.is_alias === true);
b = Number(bbb.item.is_alias === true);
if (a !== b) {
return a - b;
}
// sort by item name (lexicographically larger goes later)
let aw = aaa.word;
let bw = bbb.word;

View file

@ -0,0 +1,38 @@
// exact-check
// Checking that doc aliases are always listed after items with equivalent matching.
const EXPECTED = [
{
'query': 'coo',
'others': [
{
'path': 'doc_alias_after_other_items',
'name': 'Foo',
'href': '../doc_alias_after_other_items/struct.Foo.html',
},
{
'path': 'doc_alias_after_other_items',
'name': 'bar',
'alias': 'Boo',
'is_alias': true
},
],
},
{
'query': '"confiture"',
'others': [
{
'path': 'doc_alias_after_other_items',
'name': 'Confiture',
'href': '../doc_alias_after_other_items/struct.Confiture.html',
},
{
'path': 'doc_alias_after_other_items',
'name': 'this_is_a_long_name',
'alias': 'Confiture',
'is_alias': true
},
],
},
];

View file

@ -0,0 +1,9 @@
pub struct Foo;
#[doc(alias = "Boo")]
pub fn bar() {}
pub struct Confiture;
#[doc(alias = "Confiture")]
pub fn this_is_a_long_name() {}