Skip to content

Apache Lucene open-source search software

fix lookupWord false positive

Peter Gromov469cfc67d4ec
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/WordStorage.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/WordStorage.java
index 36e9f3fb1e0..c8bd3c56f96 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/WordStorage.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/WordStorage.java
@@ -191,7 +191,7 @@ class WordStorage {
return i == 0;
}
}
- return length == 0;
+ return length == 0 && dataPos == 0;
}
private void readForms(IntsRef forms, ByteArrayDataInput in, int length) {
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDictionary.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDictionary.java
index 1b64c3a9d31..9c7a0e06bba 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDictionary.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDictionary.java
@@ -50,6 +50,10 @@ public class TestDictionary extends LuceneTestCase {
assertNotNull(ordList);
assertEquals(1, ordList.length);
assertEquals('A', assertSingleFlag(dictionary, ordList));
+
+ assertNotNull(dictionary.lookupWord(new char[] {'a', 'b'}, 0, 2));
+ assertNotNull(dictionary.lookupWord(new char[] {'d', 'b'}, 0, 2));
+ assertNull(dictionary.lookupWord(new char[] {'b'}, 0, 1));
}
private static char assertSingleFlag(Dictionary dictionary, IntsRef ordList) {
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/simple.dic b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/simple.dic
index f7bbab3ba67..2809611b876 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/simple.dic
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/simple.dic
@@ -8,3 +8,4 @@ lucene
mahout/A
moo/E
olr/B
+db
\ No newline at end of file