Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-9764: Hunspell: try title case as FORCEUCASE misspelled word suggestions (#2352)

Peter Gromov01e34f872355
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