rustdoc: show exact case-sensitive matches first

fixes #119480
This commit is contained in:
binarycat 2024-08-22 17:13:13 -04:00
parent 5ad98b4026
commit 4c5e888eb6
2 changed files with 15 additions and 0 deletions

View File

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

View File

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