Skip to content

Apache Lucene open-source search software

hunspell GeneratingSuggester: ensure there are never more than 100 roots to process (#13154)

Peter Gromov193cc62c732a
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 4e53b7e4c54..6f150f65c9d 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -221,6 +221,8 @@ Bug Fixes
* GITHUB#13145: Detect MemorySegmentIndexInput correctly in NRTSuggester. (Uwe Schindler)
+* GITHUB#13154: Hunspell GeneratingSuggester: ensure there are never more than 100 roots to process (Peter Gromov)
+
Other
---------------------
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java
index bc07bce188f..49ebc784766 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java
@@ -88,8 +88,7 @@ class GeneratingSuggester {
CharsRef rootChars = entry.root();
sc += commonPrefix(word, rootChars) - longerWorsePenalty(word.length(), rootChars.length);
- boolean overflow = roots.size() == MAX_ROOTS;
- if (overflow && isWorseThan(sc, rootChars, roots.peek())) {
+ if (roots.size() == MAX_ROOTS && isWorseThan(sc, rootChars, roots.peek())) {
return;
}
@@ -100,7 +99,7 @@ class GeneratingSuggester {
for (int i = 0; i < forms.length; i++) {
if (isSuggestible.test(forms.ints[forms.offset + i])) {
roots.add(new Weighted<>(new Root<>(root, forms.ints[forms.offset + i]), sc));
- if (overflow) {
+ if (roots.size() == MAX_ROOTS) {
roots.poll();
}
}