Skip to content

Apache Lucene open-source search software

Hunspell suggestion: fix bug where outer isWorseCheck was ignored in `GeneratingSuggester` (#15092)

ilia-permiashkin980ab4a6ce60
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 7225c3a5a3d..78e77be8092 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -65,7 +65,7 @@ Optimizations
* GITHUB#15043: Vectorize L2 normalize function. (Ramakrishna Chilaka)
-* GITHUB#15085: Hunspell suggestions: Ensure candidate roots are not worse before updating. (Ilia Permiashkin)
+* GITHUB#15085, GITHUB#15092: Hunspell suggestions: Ensure candidate roots are not worse before updating. (Ilia Permiashkin)
Bug Fixes
---------------------
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 4e733635098..fc3e6131e71 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
@@ -28,7 +28,6 @@ import java.util.PriorityQueue;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;
-import java.util.function.IntPredicate;
import org.apache.lucene.util.CharsRef;
import org.apache.lucene.util.IntsRef;
import org.apache.lucene.util.fst.FST;
@@ -63,10 +62,6 @@ class GeneratingSuggester {
String word, WordCase originalCase) {
PriorityQueue<Weighted<Root<String>>> roots = new PriorityQueue<>(Comparator.reverseOrder());
- char[] excludeFlags = dictionary.allNonSuggestibleFlags();
- FlagEnumerator.Lookup flagLookup = dictionary.flagLookup;
- IntPredicate isSuggestible = formId -> !flagLookup.hasAnyFlag(formId, excludeFlags);
-
boolean ignoreTitleCaseRoots = originalCase == WordCase.LOWER && !dictionary.hasLanguage("de");
TrigramAutomaton automaton = new TrigramAutomaton(word);
@@ -92,21 +87,16 @@ class GeneratingSuggester {
speller.checkCanceled.run();
+ String root = rootChars.toString();
IntsRef forms = entry.forms();
- for (int i = 0; i < forms.length; i++) {
+ for (int i = 0; i < forms.length; i += dictionary.formStep()) {
int form = forms.ints[forms.offset + i];
- if (!isSuggestible.test(form)
- || roots.size() == MAX_ROOTS && isWorseThan(sc, rootChars, roots.peek())) {
- continue;
- }
-
- roots.add(new Weighted<>(new Root<>(rootChars.toString(), form), sc));
+ roots.add(new Weighted<>(new Root<>(root, form), sc));
if (roots.size() > MAX_ROOTS) {
roots.poll();
}
}
});
-
return roots.stream().sorted().toList();
}