Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-9678: Hunspell: fix off-by-one error to support prefixes of word.length - 1 (#2219)

Peter Gromov9f5bdf43b713
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.java
index 413e570f2a1..0e06d3df1ad 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
@@ -290,7 +290,7 @@ final class Stemmer {
fst.getFirstArc(arc);
IntsRef NO_OUTPUT = outputs.getNoOutput();
IntsRef output = NO_OUTPUT;
- int limit = dictionary.fullStrip ? length : length - 1;
+ int limit = dictionary.fullStrip ? length + 1 : length;
for (int i = 0; i < limit; i++) {
if (i > 0) {
int ch = word[i - 1];
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/IJ.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/IJ.aff
new file mode 100644
index 00000000000..c817c2e9132
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/IJ.aff
@@ -0,0 +1,8 @@
+# check bad capitalisation of Dutch letter IJ.
+TRY i
+FORBIDDENWORD *
+PFX i N 1
+PFX i ij IJ ij
+
+REP 1
+REP ij IJ
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/IJ.dic b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/IJ.dic
new file mode 100644
index 00000000000..ecaf91d212f
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/IJ.dic
@@ -0,0 +1,3 @@
+1
+ijs/i
+Ijs/*
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDutchIJ.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDutchIJ.java
new file mode 100644
index 00000000000..dc4b897dae3
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDutchIJ.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+package org.apache.lucene.analysis.hunspell;
+
+import org.junit.BeforeClass;
+
+public class TestDutchIJ extends StemmerTestBase {
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ init("IJ.aff", "IJ.dic");
+ }
+
+ public void testStemming() {
+ assertStemsTo("ijs", "ijs");
+ assertStemsTo("IJs", "ijs");
+ }
+}