Skip to content

Commit

Permalink
Unrolled build for rust-lang#129430
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#129430 - lolbinarycat:rustdoc-search-exact-case, r=notriddle

rustdoc: show exact case-sensitive matches first

fixes rust-lang#119480
  • Loading branch information
rust-timer authored Aug 25, 2024
2 parents f167efa + 4c5e888 commit d0745dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,7 @@ function initSearch(rawSearchIndex) {
*/
async function sortResults(results, isType, preferredCrate) {
const userQuery = parsedQuery.userQuery;
const casedUserQuery = parsedQuery.original;
const result_list = [];
for (const result of results.values()) {
result.item = searchIndex[result.id];
Expand All @@ -1403,6 +1404,13 @@ function initSearch(rawSearchIndex) {
result_list.sort((aaa, bbb) => {
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)
a = (aaa.word !== userQuery);
b = (bbb.word !== userQuery);
Expand Down
7 changes: 7 additions & 0 deletions tests/rustdoc-js-std/exact-case.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const EXPECTED = {
'query': 'Copy',
'others': [
{ 'path': 'std::marker', 'name': 'Copy' },
{ 'path': 'std::fs', 'name': 'copy' },
],
}

0 comments on commit d0745dd

Please sign in to comment.