Apache Lucene open-source search software
Fix hunspell zero-string overgeneration
Robert Muir17ca5cab582e
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex b31719ecdef..a13b673c2a8 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -159,6 +159,9 @@ Bug Fixes* LUCENE-5817: Fix hunspell zero-affix handling: previously only zero-strips workedcorrectly. (Robert Muir)+* LUCENE-5818: Fix hunspell overgeneration for short strings that also match affixes.+ (Robert Muir)+Test Framework* LUCENE-5786: Unflushed/ truncated events file (hung testing subprocess).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 216a1486ff3..e9a7a3e9184 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@@ -218,7 +218,7 @@ final class Stemmer {fst.getFirstArc(arc);IntsRef NO_OUTPUT = outputs.getNoOutput();IntsRef output = NO_OUTPUT;- for (int i = 0; i < length; i++) {+ for (int i = 0; i < length-1; i++) {if (i > 0) {int ch = word[i-1];if (fst.findTargetArc(ch, arc, arc, bytesReader) == null) {@@ -292,7 +292,7 @@ final class Stemmer {fst.getFirstArc(arc);IntsRef NO_OUTPUT = outputs.getNoOutput();IntsRef output = NO_OUTPUT;- for (int i = length; i >= 0; i--) {+ for (int i = length; i > 0; i--) {if (i < length) {int ch = word[i];if (fst.findTargetArc(ch, arc, arc, bytesReader) == null) {diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestStrangeOvergeneration.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestStrangeOvergeneration.javanew file mode 100644index 00000000000..1e85d66f619--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestStrangeOvergeneration.java@@ -0,0 +1,34 @@+package org.apache.lucene.analysis.hunspell;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import org.junit.BeforeClass;++public class TestStrangeOvergeneration extends StemmerTestBase {+ @BeforeClass+ public static void beforeClass() throws Exception {+ init("strange-overgeneration.aff", "strange-overgeneration.dic");+ }++ public void testStemming() {+ assertStemsTo("btasty", "beer");+ assertStemsTo("tasty");+ assertStemsTo("yuck");+ assertStemsTo("foo");+ }+}diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/strange-overgeneration.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/strange-overgeneration.affnew file mode 100644index 00000000000..470b570f27b--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/strange-overgeneration.aff@@ -0,0 +1,10 @@+SET UTF-8++SFX A Y 1+SFX A baz yuck baz++SFX B Y 1+SFX B bar foo .++SFX C Y 1+SFX C eer tasty .diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/strange-overgeneration.dic b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/strange-overgeneration.dicnew file mode 100644index 00000000000..e4b61b37781--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/strange-overgeneration.dic@@ -0,0 +1,5 @@+3+baz/A+bar/B+beer/C+eer/C