diff options
| author | Trevor Gross <t.gross35@gmail.com> | 2024-08-24 21:03:32 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-24 21:03:32 -0500 |
| commit | 093249af709b560ed767da588a37cafa6672ce6f (patch) | |
| tree | 97ba7bda0625b770e65fec67d8e89438906ad648 | |
| parent | 2269381e0a12aeefd21ad0b8cfcf620fc9c694a5 (diff) | |
| parent | 4c5e888eb6846d4c777bd05cbc6af06a50faeb6a (diff) | |
| download | rust-093249af709b560ed767da588a37cafa6672ce6f.tar.gz rust-093249af709b560ed767da588a37cafa6672ce6f.zip | |
Rollup merge of #129430 - lolbinarycat:rustdoc-search-exact-case, r=notriddle
rustdoc: show exact case-sensitive matches first fixes #119480
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 8 | ||||
| -rw-r--r-- | tests/rustdoc-js-std/exact-case.js | 7 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 4e3b532ae08..be0ec425946 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -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); diff --git a/tests/rustdoc-js-std/exact-case.js b/tests/rustdoc-js-std/exact-case.js new file mode 100644 index 00000000000..d9faff22fff --- /dev/null +++ b/tests/rustdoc-js-std/exact-case.js @@ -0,0 +1,7 @@ +const EXPECTED = { + 'query': 'Copy', + 'others': [ + { 'path': 'std::marker', 'name': 'Copy' }, + { 'path': 'std::fs', 'name': 'copy' }, + ], +} |
