Skip to content

fix(indexer): give lang the same tag as content_<lang> when a document brings its own language - #3450

Merged
marevol merged 1 commit into
mainfrom
fix/lang-field-normalized-tag
Sep 15, 2026
Merged

marevol merged 1 commit into
mainfrom
fix/lang-field-normalized-tag

Conversation

@marevol

@marevol marevol commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Found while verifying 15.9.0. A page that declares <html lang="zh-CN"> is indexed with lang=zh_CN, while its text is copied to content_zh-cn and a Chinese page without the attribute gets lang=zh-cn. The same language ends up in the index written two ways, and lang:zh-cn finds only the pages whose language was detected.

Cause

FessXpathTransformer stores SystemHelper#normalizeHtmlLang of the lang attribute (FessXpathTransformer.java:509-512), and SystemHelper#normalizeLang answers with the entry of supported.languages as it is spelled there, zh_CN (SystemHelper.java:586-599). Since #3394, LanguageHelper#updateDocument resolves that value through getSupportedLanguage, which returns the normalized tag zh-cn, and copies the text to content_zh-cn, but leaves lang as it found it. A detected language, on the other hand, is written to lang already normalized.

The stored value is used again later. LanguageHelper#createScript, which the label update job and the click and favorite count updates use, copies the text to content_ + lang. For a document with lang=zh_CN that is content_zh_CN, which no analyzer template in fess_indices/fess/doc.json matches (the Chinese one matches *_zh-cn).

Change

When a document already carries a lang string that resolves to a supported language, updateDocument writes the resolved tag back. That covers the lang attribute of HTML, a crawler.document.html.default.lang or crawler.document.file.default.lang configured as zh_CN, and a data store that sets lang; it applies to zh_TW, pt_BR, en_IE and ckb_IQ the same way. A value that is already normalized, such as ja, is unchanged.

SystemHelper#normalizeLang stays as it is. It also resolves the lang request parameter and the browser locale, which pass through query.language.mapping (it maps both zh_CN and zh-cn to zh-cn) to choose the content_<lang> fields to boost; they are never compared with the stored lang.

Compatibility

Documents already in the index keep lang=zh_CN until they are crawled again. A lang sent as a list through the admin documents API is left as the client sent it.

This is independent of the kana folding change to language detection in the same class; either can be merged first.

Verification

  • New LanguageHelperTest#test_updateDocument_normalizesExistingLang failed before the change (expected: <zh-cn> but was: <zh_CN>) and passes after it.
  • LanguageHelperTest: 32 tests, 0 failures.
  • mvn test: 7,488 tests, 0 failures, 0 errors.

…t brings its own language

A page declaring <html lang="zh-CN"> was indexed with lang=zh_CN while
its text went to content_zh-cn, and a Chinese page without the attribute
got lang=zh-cn. The same language was stored two ways, and lang:zh-cn
found only the pages whose language had been detected.

FessXpathTransformer stores SystemHelper#normalizeLang of the attribute,
which answers with the spelling of supported.languages, zh_CN.
LanguageHelper#updateDocument resolves it to zh-cn for the content copy
but left lang untouched. createScript, used by the label, click and
favorite count updates, then copied the text to content_zh_CN, which no
analyzer template matches.

When a document already carries a lang string that resolves to a
supported language, updateDocument now writes the resolved tag back. This
also covers crawler.document.html.default.lang and
crawler.document.file.default.lang configured as zh_CN, and pt_BR, en_IE
and ckb_IQ. SystemHelper#normalizeLang is unchanged: its request-side
values go through query.language.mapping and are never compared with the
stored lang.
@marevol marevol added this to the 15.9.0 milestone Sep 15, 2026
@marevol marevol self-assigned this Sep 15, 2026
@marevol
marevol merged commit b575d23 into main Sep 15, 2026
2 checks passed
@marevol
marevol deleted the fix/lang-field-normalized-tag branch September 16, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant