Apache Solr open-source search software
LUCENE-9721: Hunspell: disallow ONLYINCOMPOUND suffixes at the very end of compound words (#2294)
Peter Gromovd95e405fece9
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Stemmer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Stemmer.javaindex a185d5846a6..729371d0745 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Stemmer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Stemmer.java@@ -568,6 +568,12 @@ final class Stemmer {if (context != allowed && !dictionary.hasFlag(append, dictionary.compoundPermit, scratch)) {return false;}+ if (context == WordContext.COMPOUND_END+ && !isPrefix+ && !previousWasPrefix+ && dictionary.hasFlag(append, dictionary.onlyincompound, scratch)) {+ return false;+ }}if (recursionDepth == 0) {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 eedef38217e..dd5ed0c5e74 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@@ -152,6 +152,10 @@ public class SpellCheckerTest extends StemmerTestBase {doTest("compoundrule8");}+ public void testDisallowCompoundOnlySuffixesAtTheVeryEnd() throws Exception {+ doTest("onlyincompound2");+ }+public void testGermanCompounding() throws Exception {doTest("germancompounding");}diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/onlyincompound2.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/onlyincompound2.affnew file mode 100644index 00000000000..5d0ac5e69b1--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/onlyincompound2.aff@@ -0,0 +1,12 @@+# affixes only in compounds (see also fogemorpheme example)+ONLYINCOMPOUND O+COMPOUNDFLAG A+COMPOUNDPERMITFLAG P++SFX B Y 1+SFX B 0 s/OP .++# obligate fogemorpheme by forbidding the stem (0) in compounds++CHECKCOMPOUNDPATTERN 1+CHECKCOMPOUNDPATTERN 0/B /Adiff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/onlyincompound2.dic b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/onlyincompound2.dicnew file mode 100644index 00000000000..1adab653bf6--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/onlyincompound2.dic@@ -0,0 +1,3 @@+2+foo/A+pseudo/ABdiff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/onlyincompound2.good b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/onlyincompound2.goodnew file mode 100644index 00000000000..a31ce34acae--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/onlyincompound2.good@@ -0,0 +1,3 @@+foo+foopseudo+pseudosfoodiff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/onlyincompound2.wrong b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/onlyincompound2.wrongnew file mode 100644index 00000000000..29a71a3c3ba--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/onlyincompound2.wrong@@ -0,0 +1,3 @@+pseudos+foopseudos+pseudofoo