Apache Solr open-source search software
SOLR-616 -- FileBasedSpellChecker does not apply accuracy configuration.
Shalin Shekhar Mangar91170a2535c4
diff --git a/CHANGES.txt b/CHANGES.txtindex 6599dcd356e..5898b88a5fc 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -482,6 +482,10 @@ Bug Fixes41. SOLR-501: Fix admin/analysis.jsp UTF-8 input for some other servletcontainers such as Tomcat. (Hiroaki Kawai, Lars Kotthoff via yonik)++42. SOLR-616: SpellChecker accuracy configuration is not applied for FileBasedSpellChecker.+ Apply it for FileBasedSpellChecker and IndexBasedSpellChecker both.+ (shalin)Other Changes1. SOLR-135: Moved common classes to org.apache.solr.common and altered thediff --git a/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java b/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.javaindex fd38495073d..3e91acd162d 100644--- a/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java+++ b/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java@@ -47,11 +47,13 @@ public abstract class AbstractLuceneSpellChecker extends SolrSpellChecker {public static final int DEFAULT_SUGGESTION_COUNT = 5;protected String indexDir;+ protected float accuracy = 0.5f;public static final String FIELD = "field";public String init(NamedList config, SolrResourceLoader loader) {super.init(config, loader);indexDir = (String) config.get(INDEX_DIR);+ String accuracy = (String) config.get(ACCURACY);//If indexDir is relative then create index inside core.getDataDir()if (indexDir != null) {if (!new File(indexDir).isAbsolute()) {@@ -74,6 +76,15 @@ public abstract class AbstractLuceneSpellChecker extends SolrSpellChecker {} catch (IOException e) {throw new RuntimeException(e);}+ if (accuracy != null) {+ try {+ this.accuracy = Float.parseFloat(accuracy);+ spellChecker.setAccuracy(this.accuracy);+ } catch (NumberFormatException e) {+ throw new RuntimeException(+ "Unparseable accuracy given for dictionary: " + name, e);+ }+ }return name;}diff --git a/src/java/org/apache/solr/spelling/IndexBasedSpellChecker.java b/src/java/org/apache/solr/spelling/IndexBasedSpellChecker.javaindex 8180eb05b5c..22b18dd8705 100644--- a/src/java/org/apache/solr/spelling/IndexBasedSpellChecker.java+++ b/src/java/org/apache/solr/spelling/IndexBasedSpellChecker.java@@ -48,24 +48,12 @@ public class IndexBasedSpellChecker extends AbstractLuceneSpellChecker {public static final String THRESHOLD_TOKEN_FREQUENCY = "thresholdTokenFrequency";protected float threshold;- protected float accuracy = 0.5f;protected IndexReader reader;public String init(NamedList config, SolrResourceLoader loader) {super.init(config, loader);- String accuracy = (String) config.get(ACCURACY);threshold = config.get(THRESHOLD_TOKEN_FREQUENCY) == null ? 0.0f: (Float) config.get(THRESHOLD_TOKEN_FREQUENCY);- if (accuracy != null) {- try {- this.accuracy = Float.parseFloat(accuracy);- spellChecker.setAccuracy(this.accuracy);-- } catch (NumberFormatException e) {- throw new RuntimeException(- "Unparseable accuracy given for dictionary: " + name, e);- }- }initSourceReader();return name;}