Apache Lucene open-source search software
SOLR-609: SpellCheckComps now honors defaults
Grant Ingersollf2c5515c1aaf
diff --git a/CHANGES.txt b/CHANGES.txtindex 45d7928d837..fe57edba68d 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -446,6 +446,8 @@ Bug Fixes37. SOLR-604: If the spellchecking path is relative, make it relative to the Solr Data Directory. (Shalin Shekhar Mangar via gsingers)+38. SOLR-609: SpellCheckComponent now honors defaults. (Shalin Shekhar Mangar via gsingers)+Other Changes1. SOLR-135: Moved common classes to org.apache.solr.common and altered thebuild scripts to make two jars: apache-solr-1.3.jar anddiff --git a/src/java/org/apache/solr/handler/component/SpellCheckComponent.java b/src/java/org/apache/solr/handler/component/SpellCheckComponent.javaindex b68b358ac1f..4d1c36f2425 100644--- a/src/java/org/apache/solr/handler/component/SpellCheckComponent.java+++ b/src/java/org/apache/solr/handler/component/SpellCheckComponent.java@@ -135,6 +135,9 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar@SuppressWarnings("unchecked")protected NamedList initParams;++ @SuppressWarnings("unchecked")+ protected SolrParams defaults;/*** Key is the dictionary, value is the SpellChecker for that dictionary name@@ -148,6 +151,12 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwarpublic void init(NamedList args) {super.init(args);this.initParams = args;+ if (args != null) {+ Object o = args.get("defaults");+ if (o != null && o instanceof NamedList) {+ defaults = SolrParams.toSolrParams((NamedList)o);+ }+ }}@Override@@ -187,24 +196,28 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar}if (tokens != null && tokens.isEmpty() == false) {if (spellChecker != null) {- int count = params.getInt(SPELLCHECK_COUNT, 1);+ int count = params.getInt(SPELLCHECK_COUNT, defaults.getInt(+ SPELLCHECK_COUNT, 1));boolean onlyMorePopular = params.getBool(SPELLCHECK_ONLY_MORE_POPULAR,- DEFAULT_ONLY_MORE_POPULAR);+ defaults.getBool(SPELLCHECK_ONLY_MORE_POPULAR,+ DEFAULT_ONLY_MORE_POPULAR));boolean extendedResults = params.getBool(SPELLCHECK_EXTENDED_RESULTS,- false);+ defaults.getBool(SPELLCHECK_EXTENDED_RESULTS, false));NamedList response = new SimpleOrderedMap();IndexReader reader = rb.req.getSearcher().getReader();- boolean collate = params.getBool(SPELLCHECK_COLLATE, false);- SpellingResult spellingResult = spellChecker.getSuggestions(tokens, reader, count, onlyMorePopular,- extendedResults);+ boolean collate = params.getBool(SPELLCHECK_COLLATE, defaults.getBool(+ SPELLCHECK_COLLATE, false));+ SpellingResult spellingResult = spellChecker.getSuggestions(tokens,+ reader, count, onlyMorePopular, extendedResults);if (spellingResult != null) {- response.add("suggestions", toNamedList(spellingResult, q, extendedResults, collate));+ response.add("suggestions", toNamedList(spellingResult, q,+ extendedResults, collate));rb.rsp.add("spellcheck", response);}} else {throw new SolrException(SolrException.ErrorCode.NOT_FOUND,- "Specified dictionary does not exist.");+ "Specified dictionary does not exist.");}}}