うろちょろ
2025-12-02 ec26ebcc9e53f67f6242266556ed13445e2f9688
refs
author うろちょろ <112748593+chiyonn@users.noreply.github.com>
Tuesday, December 2, 2025 18:04 +0000
committer GitHub <noreply@github.com>
Tuesday, December 2, 2025 18:04 +0000
commitec26ebcc9e53f67f6242266556ed13445e2f9688
tree d153111b09f30f5cc6660bc99c52c03ebfea3e4f tree | zip | gz
parent 19e324d914a317552529d4cb87fb9794228a089e view | diff
feat: improve search tokenization for CJK languages (#2231)

* feat: improve search tokenization for CJK languages

Enhance the encoder function to properly tokenize CJK (Chinese, Japanese,
Korean) characters while maintaining English word tokenization. This fixes
search issues where CJK text was not searchable due to whitespace-only
splitting.

Changes:
- Tokenize CJK characters (Hiragana, Katakana, Kanji, Hangul) individually
- Preserve whitespace-based tokenization for non-CJK text
- Support mixed CJK/English content in search queries

This addresses the CJK search issues reported in #2109 where Japanese text
like "て以来" was not searchable because the encoder only split on whitespace.

Tested with Japanese, Chinese, and Korean content to verify character-level
tokenization works correctly while maintaining English search functionality.

* perf: optimize CJK search encoder with manual buffer tracking

Replace regex-based tokenization with index-based buffer management.
This improves performance by ~2.93x according to benchmark results.

- Use explicit buffer start/end indices instead of string concatenation
- Replace split(/\s+/) with direct whitespace code point checks
- Remove redundant filter() operations
- Add CJK Extension A support (U+20000-U+2A6DF)

Performance: ~878ms → ~300ms (100 iterations, mixed CJK/English text)

* test: add comprehensive unit tests for CJK search encoder

Add 21 unit tests covering:
- English word tokenization
- CJK character-level tokenization (Japanese, Korean, Chinese)
- Mixed CJK/English content
- Edge cases

All tests pass, confirming the encoder correctly handles CJK text.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
1 files added
1 files modified
211 ■■■■■ changed files
quartz/components/scripts/search.inline.ts 48 ●●●● diff | view | raw | blame | history
quartz/components/scripts/search.test.ts 163 ●●●●● diff | view | raw | blame | history