You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2021/02/19 19:17:51 UTC

[lucene-solr] branch master updated: LUCENE-9786: Hunspell suggestions: try moving the last character into the middle (#2399)

This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 5325d2e  LUCENE-9786: Hunspell suggestions: try moving the last character into the middle (#2399)
5325d2e is described below

commit 5325d2e6f47381ba0884ad233fdc2a11192269ee
Author: Peter Gromov <pe...@jetbrains.com>
AuthorDate: Fri Feb 19 20:15:57 2021 +0100

    LUCENE-9786: Hunspell suggestions: try moving the last character into the middle (#2399)
---
 .../java/org/apache/lucene/analysis/hunspell/ModifyingSuggester.java | 5 ++++-
 .../common/src/test/org/apache/lucene/analysis/hunspell/sug.aff      | 2 +-
 .../common/src/test/org/apache/lucene/analysis/hunspell/sug.dic      | 3 +++
 .../common/src/test/org/apache/lucene/analysis/hunspell/sug.sug      | 2 +-
 .../common/src/test/org/apache/lucene/analysis/hunspell/sug.wrong    | 3 ++-
 5 files changed, 11 insertions(+), 4 deletions(-)

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.java
index 86b6fc5..b689a69 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.aff
index a963c96..15080ba 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 testing
 MAXNGRAMSUGS 0
-TRY -
+TRY -b
 REP 2
 REP alot a_lot
 REP inspite in_spite
diff --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.dic
index 1d019ce..6725561 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/?
 in
 spite
 inspire
+Saiph
+sahib
+ship
\ No newline at end of file
diff --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.sug
index 9df0cb5..4595756 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 @@ Gandhi
 McDonald
 permanent
 in, in a
-
+Saiph, Ship, Sahib
diff --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.wrong
index 470d6f5..d8875d8 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 @@ Mcdonald
 permqnent
 permanent-vacation
 permqnent-vacation
-ina
\ No newline at end of file
+ina
+Sahip
\ No newline at end of file