Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-9702: Hunspell: support alternate casing for short language codes (#2253)

Peter Gromovff943ece8fce
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
index f38ab59b64f..4dc76abfd79 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
@@ -374,7 +374,9 @@ public class Dictionary {
fullStrip = true;
} else if ("LANG".equals(firstWord)) {
language = singleArgument(reader, line);
- alternateCasing = "tr_TR".equals(language) || "az_AZ".equals(language);
+ int underscore = language.indexOf("_");
+ String langCode = underscore < 0 ? language : language.substring(0, underscore);
+ alternateCasing = langCode.equals("tr") || langCode.equals("az");
} else if ("BREAK".equals(firstWord)) {
breaks = parseBreaks(reader, line);
} else if ("FORBIDDENWORD".equals(firstWord)) {
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/SpellCheckerTest.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/SpellCheckerTest.java
index a51a43b1882..4c5601bb7bc 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/SpellCheckerTest.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/SpellCheckerTest.java
@@ -56,6 +56,11 @@ public class SpellCheckerTest extends StemmerTestBase {
doTest("i53643");
}
+ @Test
+ public void dotless_i() throws Exception {
+ doTest("dotless_i");
+ }
+
@Test
public void needAffixOnAffixes() throws Exception {
doTest("needaffix5");
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/dotless_i.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/dotless_i.aff
new file mode 100644
index 00000000000..e9b3a60ea44
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/dotless_i.aff
@@ -0,0 +1,2 @@
+SET UTF-8
+LANG tr
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/dotless_i.dic b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/dotless_i.dic
new file mode 100644
index 00000000000..07452bafbaf
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/dotless_i.dic
@@ -0,0 +1,4 @@
+3
+iç
+ışık
+Diyarbakır
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/dotless_i.good b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/dotless_i.good
new file mode 100644
index 00000000000..50f046b60ac
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/dotless_i.good
@@ -0,0 +1,8 @@
+Diyarbakır
+DİYARBAKIR
+iç
+İç
+ışık
+Işık
+İÇ
+IŞIK
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/dotless_i.wrong b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/dotless_i.wrong
new file mode 100644
index 00000000000..ddd49d3f8e9
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/dotless_i.wrong
@@ -0,0 +1,6 @@
+Diyarbakir
+DIYARBAKIR
+Iç
+İşık
+IÇ
+İŞIK