LUCENE-9804: Hunspell: fix most similar dictionary entry search by reversing the comparator (#2419)

This commit is contained in:
Peter Gromov 2021-02-23 12:58:22 +01:00 committed by GitHub
parent 342ea856d3
commit c61b458719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 211 additions and 1 deletions

View File

@ -22,6 +22,7 @@ import static org.apache.lucene.analysis.hunspell.Dictionary.AFFIX_STRIP_ORD;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.LinkedHashSet;
import java.util.List;
@ -60,7 +61,8 @@ class GeneratingSuggester {
private List<Weighted<Root<String>>> findSimilarDictionaryEntries(
String word, WordCase originalCase) {
PriorityQueue<Weighted<Root<String>>> roots = new PriorityQueue<>();
Comparator<Weighted<Root<String>>> natural = Comparator.naturalOrder();
PriorityQueue<Weighted<Root<String>>> roots = new PriorityQueue<>(natural.reversed());
processFST(
dictionary.words,
(key, forms) -> {

View File

@ -201,6 +201,10 @@ public class TestSpellChecking extends LuceneTestCase {
doTest("sug2");
}
public void testGeneratedSuggestions() throws Exception {
doTest("ngram");
}
public void testMaxNGramSugsDefaultIsNotUnlimited() throws Exception {
doTest("maxNGramSugsDefault");
}

View File

@ -0,0 +1,202 @@
100
A
AA
AAA
AB
ABA
ABC
ABM
ABS
AC
ACLU
ACT
ACTH
AD
ADC
ADD
ADM
ADP
AF
AFAIK
AFB
AFC
AFDC
AFN
AFT
AI
AIDS
AK
AL
AM
AMA
AMD
ANSI
ANZUS
AOL
AP
APB
APC
API
APO
APR
AR
ARC
ASAP
ASCII
ASL
ASPCA
ATM
ATP
ATV
AV
AVI
AWACS
AWOL
AWS
AZ
AZT
Aachen
Aaliyah
Aaron
Abbas
Abbasid
Abbott
Abby
Abdul
Abe
Abel
Abelard
Abelson
Aberdeen
Abernathy
Abidjan
Abigail
Abilene
Abner
Aborigine
Abraham
Abram
Abrams
Absalom
Abuja
Abyssinia
Abyssinian
Ac
Acadia
Acapulco
Accenture
Accra
Acevedo
Achaean
Achebe
Achernar
Acheson
Achilles
Aconcagua
Acosta
Acropolis
Acrux
Actaeon
Acton
Acts
Acuff
thermostat
squeaker
Theron
heather
taker
Thermos
thinker
theorist
theorize
theatrics
therapeutic
lawbreaker
Northeast
weather
tiebreaker
their
therm
there
therefor
theta
theoretic
thereunder
Theiler
therapist
thematic
therewith
icebreaker
Thespian
sneaker
theater
breaker
speaker
Heather
Whitaker
toolmaker
Dorothea
Thermopylae
thereto
theocracy
thereby
ethereal
theremin
caretaker
thereat
Theravada
threadlike
therein
thereafter
thereupon
streaker
thereof
they're
thereon
jawbreaker
shoemaker
shaker
threader
Thackeray
thermionic
heartbreak
therapy
thesauri
feathery
theatricals
takeover
leather
thespian
thunderhead
Katheryn
thereunto
thereabout
feather
Shaker
therefrom
Thea
leathery
beaker
therefore
thesaurus
homemaker
theory
theorem
theocratic
Therese
Theresa
Theodore
Theodora
Theodoric
teakettle
Thatcher
theatergoer
Katherine
watchmaker
theatrical
haymaker
breather
thither
thwacker
thermal
thermos

View File

@ -0,0 +1 @@
Theater, Heather, Thereat