GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): message search keeps results when a short non-Latin word differs in case by MarcoDotIO · Pull Request #30332 · pingdotgg/t3code

fix(server): message search keeps results when a short non-Latin word differs in case #30332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
maria-rcks merged 2 commits into pingdotgg:main from MarcoDotIO:fix/search-short-tokens
Nov 6, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix(server): message search keeps results when a short non-Latin word differs in case #30332

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
a00ca2a
fix(server): message search keeps results when a short non-Latin word…
MarcoDotIO Nov 3, 2026
6c9fa82
fix(server): short non-Latin search words narrow hits before the limit
MarcoDotIO Nov 3, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
fix(server): short non-Latin search words narrow hits before the limit
Skipping the SQL check let newer messages with only the long word fill the hit limit before the matcher rejected them. Each short word is now checked as the case and accent spellings it can match, so the filter still runs first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@MarcoDotIO @claude
MarcoDotIO and claude committed Nov 3, 2026
commit 6c9fa82fd2c3778da8d7894714ff5796ea80a0b8

There are no files selected for viewing

45 changes: 44 additions & 1 deletion 45 apps/server/src/orchestration-v2/ThreadSearch.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ it.layer(layerTest)("ThreadSearch", (it) => {
for (const match of ['"needle"', null]) {
const plan = yield* sql<{
readonly detail: string;
}>`EXPLAIN QUERY PLAN ${ThreadSearch.messageHitsQuery(sql, { match, substrings: "[]", projectId: null, excludedThreadIds: "[]" })}`;
}>`EXPLAIN QUERY PLAN ${ThreadSearch.messageHitsQuery(sql, { match, substrings: "[]", shortSpellings: "[]", projectId: null, excludedThreadIds: "[]" })}`;
assert.isFalse(
plan.some((row) => row.detail.includes("TEMP B-TREE")),
plan.map((row) => row.detail).join("\n"),
Expand Down Expand Up @@ -732,6 +732,49 @@ it.layer(layerTest)("ThreadSearch filters before it ranks", (it) => {
);
});

it.effect.each([true, false])(
"ThreadSearch narrows short words outside ASCII before the hit limit (indexed: %s)",
(indexed) =>
Effect.gen(function* () {
const projections = yield* ProjectionStore.ProjectionStoreV2;
const search = yield* ThreadSearch.ThreadSearch;
const sql = yield* SqlClient.SqlClient;
const project = ProjectId.make("project:short-limit");
const older = ThreadId.make("thread:short-older");
const newer = ThreadId.make("thread:short-newer");
yield* createProject(project);
yield* Effect.forEach(
[
thread(older, project),
message(older, "older", "user", "В логах ошибка"),
thread(newer, project),
],
projections.apply,
{ discard: true },
);
if (!indexed) {
yield* sql`DROP TRIGGER orchestration_v2_message_search_insert`;
yield* sql`DROP TRIGGER orchestration_v2_message_search_update`;
yield* sql`DROP TRIGGER orchestration_v2_message_search_delete`;
yield* sql`DROP TABLE orchestration_v2_message_search`;
}
// More newer hits for the long word than one read holds, none with the short one.
yield* sql`
WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < 2000)
INSERT INTO orchestration_v2_projection_messages
(message_id, thread_id, role, streaming, created_at, updated_at, payload_json)
SELECT 'short-newer-' || i, ${newer}, 'assistant', 0, ${DateTime.formatIso(at(5))},
${DateTime.formatIso(at(5))}, json_object('text', 'ошибка здесь')
FROM n
`;
const { matches } = yield* search.search({ query: "ошибка в" });
assert.deepEqual(
matches.map((match) => match.threadId),
[older],
);
}).pipe(Effect.provide(layerTest)),
);

it.layer(layerTest)("ThreadSearch short words outside ASCII", (it) => {
it.effect("finds them in any case or accent, with or without the index", () =>
Effect.gen(function* () {
Expand Down
27 changes: 24 additions & 3 deletions 27 apps/server/src/orchestration-v2/ThreadSearch.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const SearchRequest = Schema.Struct({
match: Schema.NullOr(Schema.String),
/** Tokens every hit must contain, checked on the text. */
substrings: TokenList,
/** For each short word outside ASCII, the spellings a hit must contain one of. */
shortSpellings: Schema.fromJsonString(Schema.Array(Schema.Array(Schema.String))),
projectId: Schema.NullOr(ProjectId),
/** Threads the caller already lists, left out before the hit limit. */
excludedThreadIds: TokenList,
Expand Down Expand Up @@ -101,6 +103,19 @@ const MESSAGE_CANDIDATE_LIMIT = 10_000;
const MESSAGE_SCAN_LIMIT = 20_000;
const NON_ASCII = /[\u0080-\uffff]/;

/** SQLite's lower() folds ASCII only, so a short word is checked as each spelling it can match. */
function shortTokenSpellings(token: string): ReadonlyArray<string> {
const forms = (char: string) => {
const plain = char.normalize("NFD").replace(/\p{M}/gu, "");
return [char, char.toUpperCase(), plain, plain.toUpperCase()];
};
const spellings = Array.from(token).reduce<ReadonlyArray<string>>(
(prefixes, char) => prefixes.flatMap((prefix) => forms(char).map((form) => prefix + form)),
[""],
);
return [...new Set(spellings)];
}

/**
* The SQL inputs for a message search, or null when the query has no token
* long enough to search. Tokens of three or more characters go to the
Expand All @@ -115,12 +130,11 @@ function buildMessageSearch(
if (long.length === 0) return null;
// Two-character CJK words are too short for trigrams.
const indexed = hasIndex && long.every((token) => Array.from(token).length >= 3);
// SQLite's lower() folds ASCII only, so "в" would reject a message that has "В". The matcher
// still requires these tokens, ignoring case and accents.
const narrowing = short.filter((token) => !NON_ASCII.test(token));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

return {
match: indexed ? long.map((token) => `"${token.replaceAll('"', '""')}"`).join(" ") : null,
substrings: indexed ? narrowing : [...long, ...narrowing],
shortSpellings: short.filter((token) => NON_ASCII.test(token)).map(shortTokenSpellings),
};
}

Expand Down Expand Up @@ -164,7 +178,7 @@ export function buildSearchSnippet(text: string, matchStart: number): string {
// The scan folds ASCII case only, so accent variants and non-ASCII case variants may not match.
export const messageHitsQuery = (
sql: SqlClient.SqlClient,
{ match, substrings, projectId, excludedThreadIds }: typeof SearchRequest.Encoded,
{ match, substrings, shortSpellings, projectId, excludedThreadIds }: typeof SearchRequest.Encoded,
) => sql`
WITH eligible AS MATERIALIZED (
SELECT threads.thread_id, threads.project_id
Expand Down Expand Up @@ -229,6 +243,13 @@ export const messageHitsQuery = (
SELECT 1 FROM json_each(${substrings}) AS token
WHERE instr(lower(json_extract(messages.payload_json, '$.text')), token.value) = 0
)
AND NOT EXISTS (
SELECT 1 FROM json_each(${shortSpellings}) AS token
WHERE NOT EXISTS (
SELECT 1 FROM json_each(token.value) AS spelling
WHERE instr(json_extract(messages.payload_json, '$.text'), spelling.value) > 0
)
)
-- The index's own rowid, so FTS5 returns hits newest first and stops at
-- the limit; ordering by the messages table's rowid sorts every hit.
ORDER BY "messageRowid" DESC
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.