fix(search): make explore find symbols named in CJK (Chinese/Japanese/Korean)#1262
Open
yimingll wants to merge 1 commit into
Open
fix(search): make explore find symbols named in CJK (Chinese/Japanese/Korean)#1262yimingll wants to merge 1 commit into
yimingll wants to merge 1 commit into
Conversation
`explore` returned "No relevant code found" for a query written in Chinese /
Japanese / Korean, even though those symbols are indexed and `query` / `node`
find them.
Root cause: extractSearchTerms() tokenizes with an ASCII-only split
(`normalised.split(/[^a-zA-Z0-9]+/)`). For an all-ideographic query every
character is a separator, so it returns []. context/index.ts then skips the
text search (`if (searchTerms.length > 0)`) and explore surfaces nothing.
Fix: after the existing ASCII pass (left untouched), additively recover each
ideographic run (Han/Hiragana/Katakana/Hangul) as a term. FTS5's default
unicode61 tokenizer already stores such a run as a single token, so a
whole-run term matches exactly the way query/node do. Two-char floor since an
ideographic word is 1-2 characters ("寻路" = pathfinding).
Adds __tests__/extract-search-terms-cjk.test.ts.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
codegraph_explore/codegraph explorereturns "No relevant code found" for a query written in a CJK script (Chinese, Japanese, Korean) — even when the symbol is indexed andcodegraph query/codegraph nodefind it with the same string.Repro on a Chinese-named codebase:
Root cause
explorederives its search terms viaextractSearchTerms()(src/search/query-utils.ts), whose final tokenization is ASCII-only:For an all-ideographic query every character matches
[^a-zA-Z0-9], so the split yields only empty strings and the function returns[].context/index.tsthen guards the text search withif (searchTerms.length > 0), so nothing is searched.query/nodeare unaffected because they pass the raw string straight to FTS.Fix
After the existing ASCII pass (left completely untouched — no change to Latin/accent behaviour), additively recover each ideographic run (
\p{Script=Han|Hiragana|Katakana|Hangul}) as its own term. FTS5's defaultunicode61tokenizer already stores such a run as a single token (which is exactly whyqueryworks), so a whole-run term matches the same way. The floor is 2 chars rather than the ≥3 used to strip short ASCII noise, because an ideographic word is 1–2 characters (寻路= "pathfinding").Tests
__tests__/extract-search-terms-cjk.test.ts— 7 cases (Han / Kana / Hangul, 2-char words, mixed Latin+Han, plus ASCII-unchanged guards).npm testis green apart from a few pre-existing, unrelated failures on my Windows box (arkts-resolution,frameworks-integration,mcp-roots,mcp-initialize, plus tinypool "Worker exited unexpectedly"). I verified those fail identically with this change stashed, so they are environmental, not from this PR.Scope / possible follow-up
This fixes symbol-name / identifier queries (the common case — "find
寻路服务"). A CJK natural-language question has no word spacing, so it still tokenizes as one long run; proper CJK word segmentation would be a separate, larger change.🤖 Generated with Claude Code