GeezerVison is showing github.com — fix(server): message search keeps results when a short non-Latin word… · pingdotgg/t3code@a00ca2a
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ThreadSearch.test.ts +36Lines changed: 36 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -732,6 +732,42 @@ it.layer(layerTest)("ThreadSearch filters before it ranks", (it) => { | 732 | 732 | ); | 733 | 733 | }); | 734 | 734 |
| | 735 | +it.layer(layerTest)("ThreadSearch short words outside ASCII", (it) => { | | 736 | + it.effect("finds them in any case or accent, with or without the index", () => | | 737 | + Effect.gen(function* () { | | 738 | + const projections = yield* ProjectionStore.ProjectionStoreV2; | | 739 | + const search = yield* ThreadSearch.ThreadSearch; | | 740 | + const sql = yield* SqlClient.SqlClient; | | 741 | + const project = ProjectId.make("project:short-non-ascii"); | | 742 | + const russian = ThreadId.make("thread:short-russian"); | | 743 | + const french = ThreadId.make("thread:short-french"); | | 744 | + yield* createProject(project); | | 745 | + yield* Effect.forEach( | | 746 | + [ | | 747 | + thread(russian, project), | | 748 | + message(russian, "russian", "user", "В логах ошибка"), | | 749 | + thread(french, project), | | 750 | + message(french, "french", "user", "École fermée à Lyon"), | | 751 | + ], | | 752 | + projections.apply, | | 753 | + { discard: true }, | | 754 | + ); | | 755 | + const threadIds = (query: string) => | | 756 | + search.search({ query }).pipe(Effect.map(({ matches }) => matches.map((m) => m.threadId))); | | 757 | + | | 758 | + const assertMatches = Effect.gen(function* () { | | 759 | + assert.deepEqual(yield* threadIds("ошибка в"), [russian]); | | 760 | + assert.deepEqual(yield* threadIds("fermée éc"), [french]); | | 761 | + // They still narrow: a word the message lacks rules it out. | | 762 | + assert.deepEqual(yield* threadIds("ошибка я"), []); | | 763 | + }); | | 764 | + yield* assertMatches; | | 765 | + yield* sql`DROP TABLE orchestration_v2_message_search`; | | 766 | + yield* assertMatches; | | 767 | + }), | | 768 | + ); | | 769 | +}); | | 770 | + | 735 | 771 | it.layer(layerTest)("ThreadSearch across scripts and without the index", (it) => { | 736 | 772 | it.effect( | 737 | 773 | "matches Korean, Japanese, and two-character Chinese words, and whole short words", | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ThreadSearch.ts +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -99,6 +99,7 @@ const MESSAGE_HIT_LIMIT = 2000; | 99 | 99 | const MESSAGE_CANDIDATE_LIMIT = 10_000; | 100 | 100 | // Without the index, how many of the newest messages a search scans. | 101 | 101 | const MESSAGE_SCAN_LIMIT = 20_000; | | 102 | +const NON_ASCII = /[\u0080-\uffff]/; | 102 | 103 |
| 103 | 104 | /** | 104 | 105 | * The SQL inputs for a message search, or null when the query has no token | @@ -114,9 +115,12 @@ function buildMessageSearch( | 114 | 115 | if (long.length === 0) return null; | 115 | 116 | // Two-character CJK words are too short for trigrams. | 116 | 117 | const indexed = hasIndex && long.every((token) => Array.from(token).length >= 3); | | 118 | + // SQLite's lower() folds ASCII only, so "в" would reject a message that has "В". The matcher | | 119 | + // still requires these tokens, ignoring case and accents. | | 120 | + const narrowing = short.filter((token) => !NON_ASCII.test(token)); | 117 | 121 | return { | 118 | 122 | match: indexed ? long.map((token) => `"${token.replaceAll('"', '""')}"`).join(" ") : null, | 119 | | - substrings: indexed ? short : [...long, ...short], | | 123 | + substrings: indexed ? narrowing : [...long, ...narrowing], | 120 | 124 | }; | 121 | 125 | } | 122 | 126 |
| |
|