From 01e34f8723559f6770c63dc17cafb4a0313030a8 Mon Sep 17 00:00:00 2001 From: Peter Gromov Date: Thu, 11 Feb 2021 15:12:58 +0100 Subject: [PATCH] LUCENE-9764: Hunspell: try title case as FORCEUCASE misspelled word suggestions (#2352) --- .../org/apache/lucene/analysis/hunspell/SpellChecker.java | 7 +++++++ .../org/apache/lucene/analysis/hunspell/forceucase.sug | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/forceucase.sug 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 97dea149a51..11c05406d07 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 00000000000..6a77cbd06d0 --- /dev/null +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/forceucase.sug @@ -0,0 +1,2 @@ +Foobaz +Foobarbaz