mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
parent
5ad98b4026
commit
4c5e888eb6
@ -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);
|
||||
|
7
tests/rustdoc-js-std/exact-case.js
Normal file
7
tests/rustdoc-js-std/exact-case.js
Normal file
@ -0,0 +1,7 @@
|
||||
const EXPECTED = {
|
||||
'query': 'Copy',
|
||||
'others': [
|
||||
{ 'path': 'std::marker', 'name': 'Copy' },
|
||||
{ 'path': 'std::fs', 'name': 'copy' },
|
||||
],
|
||||
}
|
Loading…
Reference in New Issue
Block a user