Rollup merge of #129430 - lolbinarycat:rustdoc-search-exact-case, r=notriddle

rustdoc: show exact case-sensitive matches first

fixes #119480
This commit is contained in:
Trevor Gross 2024-08-24 21:03:32 -05:00 committed by GitHub
commit 093249af70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -1393,6 +1393,7 @@ function initSearch(rawSearchIndex) {
*/ */
async function sortResults(results, isType, preferredCrate) { async function sortResults(results, isType, preferredCrate) {
const userQuery = parsedQuery.userQuery; const userQuery = parsedQuery.userQuery;
const casedUserQuery = parsedQuery.original;
const result_list = []; const result_list = [];
for (const result of results.values()) { for (const result of results.values()) {
result.item = searchIndex[result.id]; result.item = searchIndex[result.id];
@ -1403,6 +1404,13 @@ function initSearch(rawSearchIndex) {
result_list.sort((aaa, bbb) => { result_list.sort((aaa, bbb) => {
let a, b; let a, b;
// sort by exact case-sensitive match
a = (aaa.item.name !== casedUserQuery);
b = (bbb.item.name !== casedUserQuery);
if (a !== b) {
return a - b;
}
// sort by exact match with regard to the last word (mismatch goes later) // sort by exact match with regard to the last word (mismatch goes later)
a = (aaa.word !== userQuery); a = (aaa.word !== userQuery);
b = (bbb.word !== userQuery); b = (bbb.word !== userQuery);

View File

@ -0,0 +1,7 @@
const EXPECTED = {
'query': 'Copy',
'others': [
{ 'path': 'std::marker', 'name': 'Copy' },
{ 'path': 'std::fs', 'name': 'copy' },
],
}