Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/shared/src/paletteSearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,14 @@ describe("rankSearchGroups with keywords and picks", () => {
scoreThreadSearch("arch", thread("Notes", { branch: "research-extension-system" }), NOW),
).toBeNull();
expect(scoreThreadSearch("arch", thread("Research notes"), NOW)?.quality).toBe(0.3);
// Except a number's last digits in a name, never in a pull request number.
expect(scoreSearchTerms("120", ["33120", "~/courses/33120"])?.quality).toBe(0.3);
expect(scoreThreadSearch("120", thread("33120 notes"), NOW)?.quality).toBe(0.3);
expect(scoreSearchTerms("312", ["33120"])).toBeNull();
expect(scoreSearchTerms("20", ["33120"])).toBeNull();
expect(
scoreThreadSearch("189", thread("Stats", { pullRequests: [{ number: 22189 }] }), NOW),
).toBeNull();
});

it("forgives typos in names but not in hidden keywords", () => {
Expand Down
21 changes: 19 additions & 2 deletions packages/shared/src/paletteSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,22 @@ interface TokenMatch extends SearchRange {
readonly letters?: ReadonlyArray<SearchRange>;
}

const NUMBER = /^\p{N}+$/u;

// A name's number ends with what people remember of it: "120" finds course "33120".
function endsNumber(field: SearchField, token: string, index: number): boolean {
const end = index + token.length;
return (
token.length >= 3 &&
NUMBER.test(token) &&
DIGIT.test(field.text[index - 1] ?? "") &&
!DIGIT.test(field.text[end] ?? "")
);
}

/**
* Mid-word hits need four or more characters and `midWord`, so "del" does not find "model".
* Mid-word hits need four or more characters and `midWord`, so "del" does not find "model",
* or a name's number ending in the token.
* Typos preserve the first letter except for swaps; short tokens allow fewer edits to limit noise.
* Numbers never match with a typo because different pull request numbers must stay distinct.
*/
Expand Down Expand Up @@ -227,7 +241,10 @@ function matchToken(
best = { score, start: index, end: index + token.length };
}
if (score === WHOLE_WORD) return best;
} else if (midWord && token.length >= 4 && best === null) {
} else if (
best === null &&
((midWord && token.length >= 4) || (isPrimary && endsNumber(field, token, index)))
) {
best = { score: MID_WORD, start: index, end: index + token.length };
}
}
Expand Down
Loading