Skip to content
Merged
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
11 changes: 10 additions & 1 deletion packages/app/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ export function rankField(value: string, query: string, field: string): RankedSe
if (haystack === needle) return { score: field === "session" ? 2 : 0, field, range: { start: 0, end: value.length } };
const start = haystack.indexOf(needle);
if (start >= 0) return { score: field === "session" ? 2 : 1, field, range: { start, end: start + needle.length } };
return null;
// Keep the useful VS Code-style behavior for queries whose characters are
// separated in the field (for example, "gen2098" matching "GEN-2098").
// This is deliberately a lower-ranked fallback than a contiguous match.
const ranges = searchMatches(value, query);
if (!ranges.length) return null;
return {
score: field === "session" ? 3 : 2,
field,
range: { start: ranges[0]!.start, end: ranges.at(-1)!.end },
};
}

export function sessionExcerpt(value: string, range: SearchMatch, radius = 90): string {
Expand Down
5 changes: 5 additions & 0 deletions packages/app/test/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ describe("global search", () => {
expect(rankField("GEN-2098", "gen-2098", "issue_id")?.score).toBe(0);
expect(rankField("notes mention GEN-2098", "gen-2098", "session")?.score).toBe(2);
});
it("matches ordered query characters across gaps", () => {
const match = rankField("Dispatch after GEN-2098 update", "gen2098", "run_name");
expect(match?.score).toBe(2);
expect(match?.range).toEqual({ start: 15, end: 23 });
});
it("creates bounded transcript excerpts", () => {
const value = "a".repeat(100) + " GEN-2098 " + "b".repeat(100);
expect(sessionExcerpt(value, { start: 101, end: 108 }, 10)).toContain("GEN-2098");
Expand Down