diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 8b23c72ac4b..b31719ecdef 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -156,6 +156,9 @@ Bug Fixes incorrect results when grouping on fields with missing values. (海老澤 志信, hossman) +* LUCENE-5817: Fix hunspell zero-affix handling: previously only zero-strips worked + correctly. (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/Dictionary.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java index b6c75bc5749..17a4db07dd2 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 @@ -435,7 +435,7 @@ public class Dictionary { char flag = flagParsingStrategy.parseFlag(ruleArgs[1]); String strip = ruleArgs[2].equals("0") ? "" : ruleArgs[2]; - String affixArg = ruleArgs[3]; + String affixArg = ruleArgs[3].equals("0") ? "" : ruleArgs[3]; char appendFlags[] = null; int flagSep = affixArg.lastIndexOf('/'); @@ -452,8 +452,6 @@ public class Dictionary { twoStageAffix = true; } - // TODO: add test and fix zero-affix handling! - String condition = ruleArgs.length > 4 ? ruleArgs[4] : "."; // at least the gascon affix file has this issue if (condition.startsWith("[") && condition.indexOf(']') == -1) { diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestZeroAffix.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestZeroAffix.java new file mode 100644 index 00000000000..a1d86ef5081 --- /dev/null +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestZeroAffix.java @@ -0,0 +1,31 @@ +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 TestZeroAffix extends StemmerTestBase { + @BeforeClass + public static void beforeClass() throws Exception { + init("zeroaffix.aff", "zeroaffix.dic"); + } + + public void testStemming() { + assertStemsTo("drink", "drinksierranevada"); + } +} diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/zeroaffix.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/zeroaffix.aff new file mode 100644 index 00000000000..52c36f77b96 --- /dev/null +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/zeroaffix.aff @@ -0,0 +1,4 @@ +SET UTF-8 + +SFX X Y 1 +SFX X sierranevada 0 . diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/zeroaffix.dic b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/zeroaffix.dic new file mode 100644 index 00000000000..92c08d04d39 --- /dev/null +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/zeroaffix.dic @@ -0,0 +1,2 @@ +1 +drinksierranevada/X [VERB]