Apache Solr open-source search software
LUCENE-9753: Hunspell: disallow compounds with parts present in dictionary, space-separated (#2335)
Peter Gromov6f525302dd68
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/SpellChecker.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/SpellChecker.javaindex 482697f060a..790eca84a5c 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/SpellChecker.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/SpellChecker.java@@ -261,12 +261,16 @@ public class SpellChecker {return false;}- //noinspection RedundantIfStatementif (dictionary.checkCompoundRep&& isMisspelledSimpleWord(length + nextPartLength, originalCase)) {return false;}- return true;++ String spaceSeparated =+ new String(tail.chars, tail.offset, length)+ + " "+ + new String(tail.chars, tail.offset + length, nextPartLength);+ return !checkWord(spaceSeparated);}private boolean isMisspelledSimpleWord(int length, WordCase originalCase) {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.javaindex 441e5d8ce6b..b71b6e30ef9 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@@ -132,6 +132,10 @@ public class SpellCheckerTest extends StemmerTestBase {doTest("checkcompoundrep");}+ public void testDisallowCompoundsWhenDictionaryContainsSeparatedWordPair() throws Exception {+ doTest("wordpair");+ }+public void testCompoundrule() throws Exception {doTest("compoundrule");}diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/wordpair.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/wordpair.affnew file mode 100644index 00000000000..e788b170774--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/wordpair.aff@@ -0,0 +1,4 @@+# a dictionary word pair separated by space+# will avoid its recognition without space+# at compound word analysis+COMPOUNDFLAG Ydiff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/wordpair.dic b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/wordpair.dicnew file mode 100644index 00000000000..96fc77f7b86--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/wordpair.dic@@ -0,0 +1,4 @@+3+word/Y+compound/Y+compound worddiff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/wordpair.good b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/wordpair.goodnew file mode 100644index 00000000000..d868fce4f9e--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/wordpair.good@@ -0,0 +1,3 @@+word+compound+wordcompounddiff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/wordpair.wrong b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/wordpair.wrongnew file mode 100644index 00000000000..04ca38b4173--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/wordpair.wrong@@ -0,0 +1 @@+compoundword