mirror of https://github.com/apache/lucene.git
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:
parent
7e1e45bfb9
commit
44b77b4f40
|
@ -545,6 +545,10 @@ Bug Fixes
|
||||||
(Drew Farris via koji)
|
(Drew Farris via koji)
|
||||||
|
|
||||||
* SOLR-1973: Empty fields in XML update messages confuse DataImportHandler. (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
|
Other Changes
|
||||||
----------------------
|
----------------------
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.solr.common.params.UpdateParams;
|
||||||
import org.apache.solr.common.util.ContentStreamBase;
|
import org.apache.solr.common.util.ContentStreamBase;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.common.util.ContentStream;
|
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.SolrConfig;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.core.SolrResourceLoader;
|
import org.apache.solr.core.SolrResourceLoader;
|
||||||
|
@ -101,9 +102,7 @@ public class DataImportHandler extends RequestHandlerBase implements
|
||||||
myName = myName.replaceAll("/","_") ;
|
myName = myName.replaceAll("/","_") ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String debug = (String) initArgs.get(ENABLE_DEBUG);
|
debugEnabled = StrUtils.parseBool((String)initArgs.get(ENABLE_DEBUG), true);
|
||||||
if (debug != null && "no".equals(debug))
|
|
||||||
debugEnabled = false;
|
|
||||||
NamedList defaults = (NamedList) initArgs.get("defaults");
|
NamedList defaults = (NamedList) initArgs.get("defaults");
|
||||||
if (defaults != null) {
|
if (defaults != null) {
|
||||||
String configLoc = (String) defaults.get("config");
|
String configLoc = (String) defaults.get("config");
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.schema.IndexSchema;
|
import org.apache.solr.schema.IndexSchema;
|
||||||
import org.apache.solr.schema.SchemaField;
|
import org.apache.solr.schema.SchemaField;
|
||||||
import org.apache.solr.common.util.ContentStream;
|
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.wrapAndThrow;
|
||||||
import static org.apache.solr.handler.dataimport.DataImportHandlerException.SEVERE;
|
import static org.apache.solr.handler.dataimport.DataImportHandlerException.SEVERE;
|
||||||
|
@ -498,29 +499,28 @@ public class DataImporter {
|
||||||
if (requestParams.containsKey("command"))
|
if (requestParams.containsKey("command"))
|
||||||
command = (String) requestParams.get("command");
|
command = (String) requestParams.get("command");
|
||||||
|
|
||||||
if ("on".equals(requestParams.get("debug"))) {
|
if (StrUtils.parseBool((String)requestParams.get("debug"),false)) {
|
||||||
debug = true;
|
debug = true;
|
||||||
rows = 10;
|
rows = 10;
|
||||||
// Set default values suitable for debug mode
|
// Set default values suitable for debug mode
|
||||||
commit = false;
|
commit = false;
|
||||||
clean = false;
|
clean = false;
|
||||||
verbose = "true".equals(requestParams.get("verbose"))
|
verbose = StrUtils.parseBool((String)requestParams.get("verbose"),false);
|
||||||
|| "on".equals(requestParams.get("verbose"));
|
|
||||||
}
|
}
|
||||||
syncMode = "true".equals(requestParams.get("synchronous"));
|
syncMode = StrUtils.parseBool((String)requestParams.get("synchronous"),false);
|
||||||
if (DELTA_IMPORT_CMD.equals(command) || IMPORT_CMD.equals(command)) {
|
if (DELTA_IMPORT_CMD.equals(command) || IMPORT_CMD.equals(command)) {
|
||||||
clean = false;
|
clean = false;
|
||||||
}
|
}
|
||||||
if (requestParams.containsKey("commit"))
|
if (requestParams.containsKey("commit"))
|
||||||
commit = Boolean.parseBoolean((String) requestParams.get("commit"));
|
commit = StrUtils.parseBool((String) requestParams.get("commit"),true);
|
||||||
if (requestParams.containsKey("start"))
|
if (requestParams.containsKey("start"))
|
||||||
start = Integer.parseInt((String) requestParams.get("start"));
|
start = Integer.parseInt((String) requestParams.get("start"));
|
||||||
if (requestParams.containsKey("rows"))
|
if (requestParams.containsKey("rows"))
|
||||||
rows = Integer.parseInt((String) requestParams.get("rows"));
|
rows = Integer.parseInt((String) requestParams.get("rows"));
|
||||||
if (requestParams.containsKey("clean"))
|
if (requestParams.containsKey("clean"))
|
||||||
clean = Boolean.parseBoolean((String) requestParams.get("clean"));
|
clean = StrUtils.parseBool((String) requestParams.get("clean"),true);
|
||||||
if (requestParams.containsKey("optimize")) {
|
if (requestParams.containsKey("optimize")) {
|
||||||
optimize = Boolean.parseBoolean((String) requestParams.get("optimize"));
|
optimize = StrUtils.parseBool((String) requestParams.get("optimize"),true);
|
||||||
if (optimize)
|
if (optimize)
|
||||||
commit = true;
|
commit = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,6 +238,24 @@ public class StrUtils {
|
||||||
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "invalid boolean value: "+s );
|
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
|
* URLEncodes a value, replacing only enough chars so that
|
||||||
* the URL may be unambiguously pasted back into a browser.
|
* the URL may be unambiguously pasted back into a browser.
|
||||||
|
|
Loading…
Reference in New Issue