Apache Solr open-source search software
LUCENE-9786: Hunspell suggestions: try moving the last character into the middle (#2399)
Peter Gromov5325d2e6f473
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 86b6fc5a869..b689a69b141 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@@ -245,11 +245,14 @@ class ModifyingSuggester {private void tryMovingChar(String word) {for (int i = 0; i < word.length(); i++) {+ String prefix = word.substring(0, i);for (int j = i + 2; j < word.length() && j <= i + MAX_CHAR_DISTANCE; j++) {- String prefix = word.substring(0, i);trySuggestion(prefix + word.substring(i + 1, j) + word.charAt(i) + word.substring(j));trySuggestion(prefix + word.charAt(j) + word.substring(i, j) + word.substring(j + 1));}+ if (i < word.length() - 1) {+ trySuggestion(prefix + word.substring(i + 1) + word.charAt(i));+ }}}diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.affindex a963c96d43b..15080ba2c31 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.aff+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.aff@@ -13,7 +13,7 @@# switch off ngram suggestion for testingMAXNGRAMSUGS 0-TRY -+TRY -bREP 2REP alot a_lotREP inspite in_spitediff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.dic b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.dicindex 1d019ceb401..6725561e81f 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.dic+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.dic@@ -13,3 +13,6 @@ permanent-vacation/?inspiteinspire+Saiph+sahib+ship\ No newline at end of filediff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.sug b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.sugindex 9df0cb5f13b..4595756cc87 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.sug+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.sug@@ -12,4 +12,4 @@ GandhiMcDonaldpermanentin, in a-+Saiph, Ship, Sahibdiff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.wrong b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.wrongindex 470d6f5f766..d8875d8a571 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.wrong+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/sug.wrong@@ -13,4 +13,5 @@ Mcdonaldpermqnentpermanent-vacationpermqnent-vacation-ina\ No newline at end of file+ina+Sahip\ No newline at end of file