Skip to content

Commit 74a2164

Browse files
committed
rustdoc: show exact case-sensitive matches first
fixes rust-lang#119480
1 parent 5ad98b4 commit 74a2164

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Diff for: src/librustdoc/html/static/js/search.js

+8
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,7 @@ function initSearch(rawSearchIndex) {
13931393
*/
13941394
async function sortResults(results, isType, preferredCrate) {
13951395
const userQuery = parsedQuery.userQuery;
1396+
const casedUserQuery = parsedQuery.original;
13961397
const result_list = [];
13971398
for (const result of results.values()) {
13981399
result.item = searchIndex[result.id];
@@ -1403,6 +1404,13 @@ function initSearch(rawSearchIndex) {
14031404
result_list.sort((aaa, bbb) => {
14041405
let a, b;
14051406

1407+
// sort by exact case-sensitive match
1408+
a = (aaa.item.name !== casedUserQuery);
1409+
b = (bbb.item.name !== casedUserQuery);
1410+
if (a !== b) {
1411+
return a - b;
1412+
}
1413+
14061414
// sort by exact match with regard to the last word (mismatch goes later)
14071415
a = (aaa.word !== userQuery);
14081416
b = (bbb.word !== userQuery);

0 commit comments

Comments
 (0)