Skip to content

Commit e650554

Browse files
shivamhwpclaude
andcommitted
fix(search): keep busy threads first for queries under three letters
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 367ab7d commit e650554

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎packages/shared/src/paletteSearch.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ describe("scoreThreadSearch", () => {
4949
thread("Auth across worktrees to share", { activityAt: NOW - 90 * DAY }),
5050
]),
5151
).toEqual(["Auth across worktrees to share", "Share authentication cleanup"]);
52+
expect(
53+
rankTitles("ui", [
54+
thread("Parse ui tokens", { activityAt: NOW - 200 * DAY }),
55+
thread("Polish UIs", { activityAt: NOW, opens: { openedAt: NOW, score: 12, picks: [] } }),
56+
]),
57+
).toEqual(["Polish UIs", "Parse ui tokens"]);
5258
});
5359

5460
it("treats camelCase, kebab, path, and digit boundaries as word starts", () => {

‎packages/shared/src/paletteSearch.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,10 @@ interface WeightedSearchField {
344344
interface SearchFieldsMatch {
345345
/** Roughly 0.3 (inside a word) to 1.5 (exact title). */
346346
readonly quality: number;
347-
/** Every counted token matched a whole word at full weight, before phrase bonuses. */
347+
/**
348+
* Every counted token matched a whole word at full weight, before phrase
349+
* bonuses, and has three or more letters: "a" or "ui" is too little to go on.
350+
*/
348351
readonly wholeWords: boolean;
349352
/** Every token matched at a word start, without a typo. */
350353
readonly strong: boolean;
@@ -409,6 +412,7 @@ function matchSearchFields(
409412
const primaryRanges: SearchRange[] = [];
410413
let total = 0;
411414
let counted = 0;
415+
let shortToken = false;
412416
let strong = true;
413417
for (const token of tokens) {
414418
let best = 0;
@@ -435,6 +439,7 @@ function matchSearchFields(
435439
if (bestPrimary) primaryRanges.push(...(bestPrimary.letters ?? [bestPrimary]));
436440
total += best;
437441
counted += 1;
442+
shortToken ||= token.length < PICK_PREFIX_MIN_LENGTH;
438443
}
439444
let quality = total / counted;
440445
if (primary) {
@@ -443,7 +448,7 @@ function matchSearchFields(
443448
}
444449
return {
445450
quality,
446-
wholeWords: total >= counted * WHOLE_WORD,
451+
wholeWords: !shortToken && total >= counted * WHOLE_WORD,
447452
strong,
448453
primaryRanges: mergeRanges(primaryRanges),
449454
};

0 commit comments

Comments
 (0)