Skip to content

Commit

Permalink
rustdoc: show exact case-sensitive matches first
Browse files Browse the repository at this point in the history
  • Loading branch information
lolbinarycat committed Aug 22, 2024
1 parent 5ad98b4 commit 74a2164
Showing 1 changed file with 8 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

0 comments on commit 74a2164

Please sign in to comment.