SOLR-2221: DIH: use StrUtils.parseBool() to get values of boolean options

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1032446 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Koji Sekiguchi 2010-11-08 02:29:24 +00:00
parent 7e1e45bfb9
commit 44b77b4f40
4 changed files with 31 additions and 10 deletions

View File

@ -545,6 +545,10 @@ Bug Fixes
(Drew Farris via koji)
* SOLR-1973: Empty fields in XML update messages confuse DataImportHandler. (koji)
* SOLR-2221: Use StrUtils.parseBool() to get values of boolean options in DIH.
true/on/yes (for TRUE) and false/off/no (for FALSE) can be used for sub-options
(debug, verbose, synchronous, commit, clean, optimize) for full/delta-import commands. (koji)
Other Changes
----------------------

View File

@ -26,6 +26,7 @@ import org.apache.solr.common.params.UpdateParams;
import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.ContentStream;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrResourceLoader;
@ -101,9 +102,7 @@ public class DataImportHandler extends RequestHandlerBase implements
myName = myName.replaceAll("/","_") ;
}
}
String debug = (String) initArgs.get(ENABLE_DEBUG);
if (debug != null && "no".equals(debug))
debugEnabled = false;
debugEnabled = StrUtils.parseBool((String)initArgs.get(ENABLE_DEBUG), true);
NamedList defaults = (NamedList) initArgs.get("defaults");
if (defaults != null) {
String configLoc = (String) defaults.get("config");

View File

@ -22,6 +22,7 @@ import org.apache.solr.core.SolrCore;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.common.util.ContentStream;
import org.apache.solr.common.util.StrUtils;
import static org.apache.solr.handler.dataimport.DataImportHandlerException.wrapAndThrow;
import static org.apache.solr.handler.dataimport.DataImportHandlerException.SEVERE;
@ -498,29 +499,28 @@ public class DataImporter {
if (requestParams.containsKey("command"))
command = (String) requestParams.get("command");
if ("on".equals(requestParams.get("debug"))) {
if (StrUtils.parseBool((String)requestParams.get("debug"),false)) {
debug = true;
rows = 10;
// Set default values suitable for debug mode
commit = false;
clean = false;
verbose = "true".equals(requestParams.get("verbose"))
|| "on".equals(requestParams.get("verbose"));
verbose = StrUtils.parseBool((String)requestParams.get("verbose"),false);
}
syncMode = "true".equals(requestParams.get("synchronous"));
syncMode = StrUtils.parseBool((String)requestParams.get("synchronous"),false);
if (DELTA_IMPORT_CMD.equals(command) || IMPORT_CMD.equals(command)) {
clean = false;
}
if (requestParams.containsKey("commit"))
commit = Boolean.parseBoolean((String) requestParams.get("commit"));
commit = StrUtils.parseBool((String) requestParams.get("commit"),true);
if (requestParams.containsKey("start"))
start = Integer.parseInt((String) requestParams.get("start"));
if (requestParams.containsKey("rows"))
rows = Integer.parseInt((String) requestParams.get("rows"));
if (requestParams.containsKey("clean"))
clean = Boolean.parseBoolean((String) requestParams.get("clean"));
clean = StrUtils.parseBool((String) requestParams.get("clean"),true);
if (requestParams.containsKey("optimize")) {
optimize = Boolean.parseBoolean((String) requestParams.get("optimize"));
optimize = StrUtils.parseBool((String) requestParams.get("optimize"),true);
if (optimize)
commit = true;
}

View File

@ -238,6 +238,24 @@ public class StrUtils {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "invalid boolean value: "+s );
}
/**
* {@link NullPointerException} and {@link SolrException} free version of {@link #parseBool(String)}
* @param s
* @param def
* @return
*/
public static boolean parseBool(String s, boolean def) {
if( s != null ) {
if( s.startsWith("true") || s.startsWith("on") || s.startsWith("yes") ) {
return true;
}
if( s.startsWith("false") || s.startsWith("off") || s.equals("no") ) {
return false;
}
}
return def;
}
/**
* URLEncodes a value, replacing only enough chars so that
* the URL may be unambiguously pasted back into a browser.