Skip to content

Commit 980ab4a

Browse files
authored
Hunspell suggestion: fix bug where outer isWorseCheck was ignored in GeneratingSuggester (#15092)
* Hunspell suggestion: fix bug where outer isWorseCheck was ignored in `GeneratingSuggester` On top of that: * Remove redundant `isSuggestible` check * Use `dictionary.formStep()` to properly iterate root's forms * Add note to CHANGES.txt
1 parent 6e712fc commit 980ab4a

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

lucene/CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Optimizations
6565

6666
* GITHUB#15043: Vectorize L2 normalize function. (Ramakrishna Chilaka)
6767

68-
* GITHUB#15085: Hunspell suggestions: Ensure candidate roots are not worse before updating. (Ilia Permiashkin)
68+
* GITHUB#15085, GITHUB#15092: Hunspell suggestions: Ensure candidate roots are not worse before updating. (Ilia Permiashkin)
6969

7070
Bug Fixes
7171
---------------------

lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Set;
2929
import java.util.TreeSet;
3030
import java.util.function.Consumer;
31-
import java.util.function.IntPredicate;
3231
import org.apache.lucene.util.CharsRef;
3332
import org.apache.lucene.util.IntsRef;
3433
import org.apache.lucene.util.fst.FST;
@@ -63,10 +62,6 @@ private List<Weighted<Root<String>>> findSimilarDictionaryEntries(
6362
String word, WordCase originalCase) {
6463
PriorityQueue<Weighted<Root<String>>> roots = new PriorityQueue<>(Comparator.reverseOrder());
6564

66-
char[] excludeFlags = dictionary.allNonSuggestibleFlags();
67-
FlagEnumerator.Lookup flagLookup = dictionary.flagLookup;
68-
IntPredicate isSuggestible = formId -> !flagLookup.hasAnyFlag(formId, excludeFlags);
69-
7065
boolean ignoreTitleCaseRoots = originalCase == WordCase.LOWER && !dictionary.hasLanguage("de");
7166
TrigramAutomaton automaton = new TrigramAutomaton(word);
7267

@@ -92,21 +87,16 @@ private List<Weighted<Root<String>>> findSimilarDictionaryEntries(
9287

9388
speller.checkCanceled.run();
9489

90+
String root = rootChars.toString();
9591
IntsRef forms = entry.forms();
96-
for (int i = 0; i < forms.length; i++) {
92+
for (int i = 0; i < forms.length; i += dictionary.formStep()) {
9793
int form = forms.ints[forms.offset + i];
98-
if (!isSuggestible.test(form)
99-
|| roots.size() == MAX_ROOTS && isWorseThan(sc, rootChars, roots.peek())) {
100-
continue;
101-
}
102-
103-
roots.add(new Weighted<>(new Root<>(rootChars.toString(), form), sc));
94+
roots.add(new Weighted<>(new Root<>(root, form), sc));
10495
if (roots.size() > MAX_ROOTS) {
10596
roots.poll();
10697
}
10798
}
10899
});
109-
110100
return roots.stream().sorted().toList();
111101
}
112102

0 commit comments

Comments
 (0)