Skip to content

Commit c18b9c4

Browse files
MarcoDotIOclaude
andcommitted
fix(server): message search without the index finds words typed with a curly apostrophe
The search index stores message text with curly apostrophes straightened, and queries are straightened the same way. The substring check that the scan path (no FTS5 trigram index, or a two-character CJK word) and short tokens rely on read the raw text instead, so "gannet's" never matched "the gannet’s nest". Check the same straightened text the index stores. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 812c0a7 commit c18b9c4

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/ThreadSearch.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,35 @@ it.layer(layerTest)("ThreadSearch across scripts and without the index", (it) =>
668668
);
669669
});
670670

671+
it.layer(layerTest)("ThreadSearch without the index", (it) => {
672+
it.effect("finds a curly apostrophe for a straight one and back", () =>
673+
Effect.gen(function* () {
674+
const projections = yield* ProjectionStore.ProjectionStoreV2;
675+
const search = yield* ThreadSearch.ThreadSearch;
676+
const sql = yield* SqlClient.SqlClient;
677+
const project = ProjectId.make("project:scan-apostrophes");
678+
const curly = ThreadId.make("thread:scan-apostrophe-curly");
679+
const straight = ThreadId.make("thread:scan-apostrophe-straight");
680+
yield* createProject(project);
681+
yield* Effect.forEach(
682+
[
683+
thread(curly, project),
684+
message(curly, "scan-apostrophe-curly", "user", "the gannet’s nest"),
685+
thread(straight, project),
686+
message(straight, "scan-apostrophe-straight", "user", "a kittiwake's nest"),
687+
],
688+
projections.apply,
689+
{ discard: true },
690+
);
691+
yield* sql`DROP TABLE orchestration_v2_message_search`;
692+
const threadIds = (query: string) =>
693+
search.search({ query }).pipe(Effect.map(({ matches }) => matches.map((m) => m.threadId)));
694+
assert.deepEqual(yield* threadIds("gannet's"), [curly]);
695+
assert.deepEqual(yield* threadIds("kittiwake’s"), [straight]);
696+
}),
697+
);
698+
});
699+
671700
it.layer(layerTest)("ThreadSearch.searchOlderSettled", (it) => {
672701
it.effect("returns older settled title matches in scope, then older message hits", () =>
673702
Effect.gen(function* () {

‎apps/server/src/orchestration-v2/ThreadSearch.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
type ThreadSearchSubject,
3434
} from "@t3tools/shared/paletteSearch";
3535
import { threadSearchPullRequests } from "@t3tools/shared/threadPullRequests";
36-
import { indexedMessageCondition } from "./messageSearchIndex.ts";
36+
import { indexedMessageCondition, indexedMessageText } from "./messageSearchIndex.ts";
3737
import { loadOlderSettledThreadsPage } from "./ShellStream.ts";
3838

3939
// When the user last wrote in the thread aliased `threads`, as the clients
@@ -221,7 +221,7 @@ export const messageHitsQuery = (
221221
AND messages.message_id NOT LIKE 'async-answer:%'
222222
AND NOT EXISTS (
223223
SELECT 1 FROM json_each(${substrings}) AS token
224-
WHERE instr(lower(json_extract(messages.payload_json, '$.text')), token.value) = 0
224+
WHERE instr(lower(${indexedMessageText(sql, "messages.payload_json")}), token.value) = 0
225225
)
226226
-- The index's own rowid, so FTS5 returns hits newest first and stops at
227227
-- the limit; ordering by the messages table's rowid sorts every hit.

0 commit comments

Comments
 (0)