Skip to content

Add CJK analyzer support for Chinese, Japanese and Korean - #72

Open
SNO7E-G wants to merge 1 commit into
OnTheGoSystems:masterfrom
SNO7E-G:feat/cjk-analyzer
Open

SNO7E-G wants to merge 1 commit into
OnTheGoSystems:masterfrom
SNO7E-G:feat/cjk-analyzer

Conversation

@SNO7E-G

@SNO7E-G SNO7E-G commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

References #56 (choosing the correct language analyzer).

Problem

The analyzer map in TranslateLanguages has no entry for Chinese, Japanese or Korean, so generateAnalysisLanguages() falls back to the english analyzer for zh-hans, zh-hant, ja and ko indices. CJK text has no word separators, so standard tokenization turns whole sentences into single tokens and search on those languages is effectively broken.

Fix

One line: map those four WPML language codes to Elasticsearch's built-in cjk analyzer, which tokenizes CJK text into overlapping bigrams.

Everything downstream works through the existing wiring, unchanged:

  • Stopwords: generateIndexByIndexable() builds the stopword list as '_' . analyzer . '_' → _cjk_, which is one of Elasticsearch's predefined
    stopword lists.
  • Snowball: cjk is not in $snowballLanguages, so the snowball filter keeps its default — the same path Arabic and Thai already take.
  • Stemmer: cjk is not in $stemmerLanguages, so no stemmer filter is added — no stemmer exists for these languages (again like Arabic/Thai; see also the Thai stemmer fix in 2.0.5).

Verification

  • PHPStan (level 3): clean.
  • PHPUnit suite: passes.
  • cjk analyzer and _cjk_ stopword list verified against the Elasticsearch built-in language analyzer / stop filter references.

These languages were missing from the analyzer map, so their indices
fell back to the English analyzer. CJK text has no word separators,
so standard tokenization produces unusable tokens and search results.

Map zh-hans, zh-hant, ja and ko to the built-in cjk analyzer. The
_cjk_ predefined stopword list is applied through the existing
stopwords wiring; no snowball or stemmer exists for these languages,
which follows the same path as Arabic and Thai.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant