Apache Lucene open-source search software
Hunspell: don't proceed with other suggestions if we found good REP ones (#13156)
Peter Gromov51122f8b2e65
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 8319ac38949..578fe04456f 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -204,6 +204,8 @@ Improvements* GITHUB#13155: Hunspell: allow ignoring exceptions on duplicate ICONV/OCONV mappings (Peter Gromov)+* GITHUB#13156: Hunspell: don't proceed with other suggestions if we found good REP ones (Peter Gromov)+Optimizations---------------------diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ModifyingSuggester.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ModifyingSuggester.javaindex dbcc8f45c34..218150cb416 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ModifyingSuggester.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ModifyingSuggester.java@@ -123,7 +123,11 @@ class ModifyingSuggester {private boolean tryVariationsOf(String word) {boolean hasGoodSuggestions = trySuggestion(word.toUpperCase(Locale.ROOT));- hasGoodSuggestions |= tryRep(word);++ GradedSuggestions repResult = tryRep(word);+ if (repResult == GradedSuggestions.Best) return true;++ hasGoodSuggestions |= repResult == GradedSuggestions.Normal;if (!speller.dictionary.mapTable.isEmpty()) {enumerateMapReplacements(word, "", 0);@@ -155,12 +159,20 @@ class ModifyingSuggester {return hasGoodSuggestions;}- private boolean tryRep(String word) {+ private enum GradedSuggestions {+ None,+ Normal,+ Best+ }++ private GradedSuggestions tryRep(String word) {+ boolean hasBest = false;int before = result.size();for (RepEntry entry : speller.dictionary.repTable) {for (String candidate : entry.substitute(word)) {candidate = candidate.trim();if (trySuggestion(candidate)) {+ hasBest = true;continue;}@@ -170,7 +182,8 @@ class ModifyingSuggester {}}}- return result.size() > before;+ if (hasBest) return GradedSuggestions.Best;+ return result.size() > before ? GradedSuggestions.Normal : GradedSuggestions.None;}private void enumerateMapReplacements(String word, String accumulated, int offset) {diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/ph.sug b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/ph.sugindex 8daee56fef3..ccd936e032c 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/ph.sug+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/ph.sug@@ -1,11 +1,11 @@a lot-in spite, inspire+in spitewhatwhatWednesdayWednesdayWednesdayWednesday-which, witch, winch, wish+which, witchOh, my gosh!OH, MY GOSH!diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/rep.sug b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/rep.sugindex ec15195da6a..c58b7a8b28b 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/rep.sug+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/rep.sug@@ -5,6 +5,6 @@ a lot, lotun alunnobarvinte e un-auto's, auto+auto'sart nouveaunouveau\ No newline at end of file