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/11 14:13:14 UTC

[lucene-solr] branch master updated: LUCENE-9764: Hunspell: try title case as FORCEUCASE misspelled word suggestions (#2352)

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 01e34f8  LUCENE-9764: Hunspell: try title case as FORCEUCASE misspelled word suggestions (#2352)
01e34f8 is described below

commit 01e34f8723559f6770c63dc17cafb4a0313030a8
Author: Peter Gromov <pe...@jetbrains.com>
AuthorDate: Thu Feb 11 15:12:58 2021 +0100

    LUCENE-9764: Hunspell: try title case as FORCEUCASE misspelled word suggestions (#2352)
---
 .../src/java/org/apache/lucene/analysis/hunspell/SpellChecker.java | 7 +++++++
 .../src/test/org/apache/lucene/analysis/hunspell/forceucase.sug    | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/SpellChecker.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/SpellChecker.java
index 97dea14..11c0540 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/SpellChecker.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/SpellChecker.java
@@ -430,6 +430,13 @@ public class SpellChecker {
     }
 
     WordCase wordCase = WordCase.caseOf(word);
+    if (dictionary.forceUCase != FLAG_UNSET && wordCase == WordCase.LOWER) {
+      String title = dictionary.toTitleCase(word);
+      if (spell(title)) {
+        return Collections.singletonList(title);
+      }
+    }
+
     SpellChecker suggestionSpeller =
         new SpellChecker(dictionary) {
           @Override
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/forceucase.sug b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/forceucase.sug
new file mode 100644
index 0000000..6a77cbd
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/forceucase.sug
@@ -0,0 +1,2 @@
+Foobaz
+Foobarbaz