Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/org/codelibs/fess/helper/LanguageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ public void updateDocument(final Map<String, Object> doc) {
if (language == null) {
return;
}
} else if (doc.get(fessConfig.getIndexFieldLang()) instanceof String) {
// A language the document brings with it -- <html lang="zh-CN">, a configured default lang --
// is written the way supported.languages writes it, zh_CN. The text is copied below to the field
// of the normalized tag, content_zh-cn, so lang carries that tag too, as it does for a detected
// language; otherwise lang:zh-cn does not find the document.
doc.put(fessConfig.getIndexFieldLang(), language);
}

for (final String f : langFields) {
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/codelibs/fess/helper/LanguageHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ public void test_updateDocument_skipExistingLangFields() {
assertEquals("コンテンツ", doc.get("content_ja"));
}

@Test
public void test_updateDocument_normalizesExistingLang() {
// <html lang="zh-CN"> reaches the document as zh_CN, the spelling supported.languages uses. The
// text is copied to content_zh-cn, so lang has to carry the same tag a detected document gets,
// or lang:zh-cn does not find the page.
languageHelper.supportedLanguages = new String[] { "ja", "en", "zh_CN", "zh_TW" };
Map<String, Object> doc = new HashMap<>();
doc.put("lang", "zh_CN");
doc.put("title", "标题");
doc.put("content", "内容");

languageHelper.updateDocument(doc);

assertEquals("zh-cn", doc.get("lang"));
assertEquals("标题", doc.get("title_zh-cn"));
assertEquals("内容", doc.get("content_zh-cn"));
assertNull(doc.get("content_zh_CN"));
}

@Test
public void test_detectLanguage_blank() {
assertNull(languageHelper.detectLanguage(null));
Expand Down
Loading