Skip to content

Commit 4c5e888

Browse files
committed
rustdoc: show exact case-sensitive matches first
fixes #119480
1 parent 5ad98b4 commit 4c5e888

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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);

tests/rustdoc-js-std/exact-case.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const EXPECTED = {
2+
'query': 'Copy',
3+
'others': [
4+
{ 'path': 'std::marker', 'name': 'Copy' },
5+
{ 'path': 'std::fs', 'name': 'copy' },
6+
],
7+
}

0 commit comments

Comments
 (0)