Skip to content

Commit

Permalink
Show exact case-sensitive matches first
Browse files Browse the repository at this point in the history
  • Loading branch information
Folyd committed Aug 31, 2024
1 parent 3a8c8bd commit e63e75c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/search/docs/base-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,7 @@ export default class DocSearchV2 {
*/
const sortResults = async (results, isType, preferredCrate) => {
const userQuery = parsedQuery.userQuery;
const casedUserQuery = parsedQuery.original;
const result_list = [];
for (const result of results.values()) {
result.item = this.searchIndex[result.id];
Expand All @@ -2099,6 +2100,13 @@ export default class DocSearchV2 {
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 e63e75c

Please sign in to comment.