Skip to content

Commit c2c0259

Browse files
AndreyBozhkoAndrey Bozhkoepughcpoerschke
authored
SOLR-12089: FileBasedSpellChecker docs have some missing params (#2356)
* Now handles a accept accuracy as float. * deprecate misspelled `breakSugestionTieBreaker` parameter in favor of `breakSuggestionTieBreaker` in WordBreakSolrSpellChecker. * Audit and update the Ref Guide for missing parameters. --------- Co-authored-by: Andrey Bozhko <[email protected]> Co-authored-by: Eric Pugh <[email protected]> Co-authored-by: Christine Poerschke <[email protected]>
1 parent ab65ded commit c2c0259

File tree

12 files changed

+161
-63
lines changed

12 files changed

+161
-63
lines changed

solr/CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ Other Changes
162162

163163
* SOLR-17190: Replace org.apache.solr.util.LongSet with hppc LongHashSet (Michael Gibney)
164164

165+
* SOLR-12089: Update FileBasedSpellChecker and IndexBasedSpellChecker to accept accuracy parameter
166+
as float; deprecate `breakSugestionTieBreaker` parameter in favor of `breakSuggestionTieBreaker`
167+
in WordBreakSolrSpellChecker (Andrey Bozhko via Eric Pugh)
168+
165169
* SOLR-17201: Http2SolrClient and friends no longer marked as @lucene.experimental.
166170
Krb5HttpClientBuilder and PreemptiveBasicAuthClientBuilderFactory no longer deprecated (janhoy)
167171

solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ public void inform(SolrCore core) {
760760
private boolean addSpellChecker(SolrCore core, boolean hasDefault, NamedList<?> spellchecker) {
761761
String className = (String) spellchecker.get("classname");
762762
if (className == null) className = (String) spellchecker.get("class");
763-
// TODO: this is a little bit sneaky: warn if class isnt supplied
763+
// TODO: this is a little bit sneaky: warn if class isn't supplied
764764
// so that it's mandatory in a future release?
765765
if (className == null) className = IndexBasedSpellChecker.class.getName();
766766
SolrResourceLoader loader = core.getResourceLoader();

solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public abstract class AbstractLuceneSpellChecker extends SolrSpellChecker {
8181
public String init(NamedList<?> config, SolrCore core) {
8282
super.init(config, core);
8383
indexDir = (String) config.get(INDEX_DIR);
84-
String accuracy = (String) config.get(ACCURACY);
8584
// If indexDir is relative then create index inside core.getDataDir()
8685
if (indexDir != null) {
8786
if (!new File(indexDir).isAbsolute()) {
@@ -120,9 +119,10 @@ public String init(NamedList<?> config, SolrCore core) {
120119
} catch (IOException e) {
121120
throw new RuntimeException(e);
122121
}
122+
Object accuracy = config.get(ACCURACY);
123123
if (accuracy != null) {
124124
try {
125-
this.accuracy = Float.parseFloat(accuracy);
125+
this.accuracy = Float.parseFloat(accuracy.toString());
126126
spellChecker.setAccuracy(this.accuracy);
127127
} catch (NumberFormatException e) {
128128
throw new RuntimeException("Unparseable accuracy given for dictionary: " + name, e);

solr/core/src/java/org/apache/solr/spelling/WordBreakSolrSpellChecker.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.solr.spelling;
1818

1919
import java.io.IOException;
20+
import java.lang.invoke.MethodHandles;
2021
import java.util.ArrayList;
2122
import java.util.Collections;
2223
import java.util.Iterator;
@@ -32,6 +33,8 @@
3233
import org.apache.solr.common.util.NamedList;
3334
import org.apache.solr.core.SolrCore;
3435
import org.apache.solr.search.SolrIndexSearcher;
36+
import org.slf4j.Logger;
37+
import org.slf4j.LoggerFactory;
3538

3639
/**
3740
* A spellchecker that breaks and combines words.
@@ -46,6 +49,9 @@
4649
* properly sets these flags.
4750
*/
4851
public class WordBreakSolrSpellChecker extends SolrSpellChecker {
52+
53+
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
54+
4955
/** Try to combine multiple words into one? [true|false] */
5056
public static final String PARAM_COMBINE_WORDS = "combineWords";
5157

@@ -61,16 +67,24 @@ public class WordBreakSolrSpellChecker extends SolrSpellChecker {
6167
/** See {@link WordBreakSpellChecker#setMinBreakWordLength} */
6268
public static final String PARAM_MIN_BREAK_WORD_LENGTH = "minBreakLength";
6369

70+
/**
71+
* See {@link BreakSuggestionTieBreaker} for options.
72+
*
73+
* @deprecated Only used for backwards compatibility. It will be removed in 10.x.
74+
*/
75+
@Deprecated(since = "9.6")
76+
private static final String PARAM_BREAK_SUGESTION_TIE_BREAKER = "breakSugestionTieBreaker";
77+
6478
/** See {@link BreakSuggestionTieBreaker} for options. */
65-
public static final String PARAM_BREAK_SUGGESTION_TIE_BREAKER = "breakSugestionTieBreaker";
79+
public static final String PARAM_BREAK_SUGGESTION_TIE_BREAKER = "breakSuggestionTieBreaker";
6680

6781
/** See {@link WordBreakSpellChecker#setMaxEvaluations} */
6882
public static final String PARAM_MAX_EVALUATIONS = "maxEvaluations";
6983

7084
/** See {@link WordBreakSpellChecker#setMinSuggestionFrequency} */
7185
public static final String PARAM_MIN_SUGGESTION_FREQUENCY = "minSuggestionFreq";
7286

73-
/** Specify a value on the "breakSugestionTieBreaker" parameter. The default is MAX_FREQ. */
87+
/** Specify a value on the "breakSuggestionTieBreaker" parameter. The default is MAX_FREQ. */
7488
public enum BreakSuggestionTieBreaker {
7589
/** See {@link BreakSuggestionSortMethod#NUM_CHANGES_THEN_MAX_FREQUENCY} # */
7690
MAX_FREQ,
@@ -92,6 +106,17 @@ public String init(NamedList<?> config, SolrCore core) {
92106
breakWords = boolParam(config, PARAM_BREAK_WORDS);
93107
wbsp = new WordBreakSpellChecker();
94108
String bstb = strParam(config, PARAM_BREAK_SUGGESTION_TIE_BREAKER);
109+
if (bstb == null) {
110+
bstb = strParam(config, PARAM_BREAK_SUGESTION_TIE_BREAKER);
111+
if (bstb != null && log.isWarnEnabled()) {
112+
log.warn(
113+
"Parameter '"
114+
+ PARAM_BREAK_SUGESTION_TIE_BREAKER
115+
+ "' is deprecated and will be removed in Solr 10.x. Please use '"
116+
+ PARAM_BREAK_SUGGESTION_TIE_BREAKER
117+
+ "' instead."); // nowarn
118+
}
119+
}
95120
if (bstb != null) {
96121
bstb = bstb.toUpperCase(Locale.ROOT);
97122
if (bstb.equals(BreakSuggestionTieBreaker.SUM_FREQ.name())) {

solr/core/src/test-files/solr/collection1/conf/solrconfig-minhash.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271
<str name="name">freq</str>
272272
<str name="field">lowerfilt</str>
273273
<str name="spellcheckIndexDir">spellcheckerFreq</str>
274-
<!-- comparatorClass be one of:
274+
<!-- comparatorClass can be one of:
275275
1. score (default)
276276
2. freq (Frequency first, then score)
277277
3. A fully qualified class name

solr/core/src/test-files/solr/collection1/conf/solrconfig-plugcollector.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
<str name="name">freq</str>
260260
<str name="field">lowerfilt</str>
261261
<str name="spellcheckIndexDir">spellcheckerFreq</str>
262-
<!-- comparatorClass be one of:
262+
<!-- comparatorClass can be one of:
263263
1. score (default)
264264
2. freq (Frequency first, then score)
265265
3. A fully qualified class name

solr/core/src/test-files/solr/collection1/conf/solrconfig-spellcheckcomponent.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
<str name="field">lowerfilt</str>
8484
<str name="combineWords">true</str>
8585
<str name="breakWords">true</str>
86-
<str name="breakSugestionTieBreaker">MAX_FREQ</str>
86+
<str name="breakSuggestionTieBreaker">MAX_FREQ</str>
8787
<int name="maxChanges">10</int>
8888
</lst>
8989
<lst name="spellchecker">
@@ -122,13 +122,14 @@
122122
<str name="sourceLocation">spellings.txt</str>
123123
<str name="characterEncoding">UTF-8</str>
124124
<str name="spellcheckIndexDir">spellchecker3</str>
125+
<float name="accuracy">0.5</float>
125126
</lst>
126127
<!-- Comparator -->
127128
<lst name="spellchecker">
128129
<str name="name">freq</str>
129130
<str name="field">lowerfilt</str>
130131
<str name="spellcheckIndexDir">spellcheckerFreq</str>
131-
<!-- comparatorClass be one of:
132+
<!-- comparatorClass can be one of:
132133
1. score (default)
133134
2. freq (Frequency first, then score)
134135
3. A fully qualified class name

solr/core/src/test-files/solr/collection1/conf/solrconfig.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
<str name="name">freq</str>
279279
<str name="field">lowerfilt</str>
280280
<str name="spellcheckIndexDir">spellcheckerFreq</str>
281-
<!-- comparatorClass be one of:
281+
<!-- comparatorClass can be one of:
282282
1. score (default)
283283
2. freq (Frequency first, then score)
284284
3. A fully qualified class name

solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@
828828

829829
<!-- a spellchecker that use an alternate comparator
830830
831-
comparatorClass be one of:
831+
comparatorClass can be one of:
832832
1. score (default)
833833
2. freq (Frequency first, then score)
834834
3. A fully qualified class name

solr/solr-ref-guide/modules/query-guide/pages/function-queries.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ Uses the Lucene spell checker `StringDistance` interface and supports all of the
473473
Possible values for distance measure are:
474474

475475
* jw: Jaro-Winkler
476-
* edit: Levenstein or Edit distance
476+
* edit: Levenshtein or Edit distance
477477
* ngram: The NGramDistance, if specified, can optionally pass in the ngram size too.
478478
Default is 2.
479479
* FQN: Fully Qualified class Name for an implementation of the StringDistance interface.

0 commit comments

Comments
 (0)