SOLR-9546: Eliminate unnecessary boxing/unboxing going on in SolrParams

This commit is contained in:
Noble Paul 2016-10-21 18:58:33 +05:30
parent a08a2a2965
commit f51340993a
11 changed files with 132 additions and 76 deletions

View File

@ -184,6 +184,8 @@ Optimizations
* SOLR-9566: Don't put replicas into recovery when first creating a Collection
(Alan Woodward)
* SOLR-9546: Eliminate unnecessary boxing/unboxing going on in SolrParams (Pushkar Raste, noble)
Other Changes
----------------------

View File

@ -1887,7 +1887,7 @@ public class ZkController {
elect.setup(context);
electionContexts.put(contextKey, context);
elect.retryElection(context, params.getBool(REJOIN_AT_HEAD_PROP));
elect.retryElection(context, params.getBool(REJOIN_AT_HEAD_PROP, false));
}
} catch (Exception e) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to rejoin election", e);

View File

@ -56,13 +56,15 @@ public class DumpRequestHandler extends RequestHandlerBase
}
}
if(Boolean.TRUE.equals( req.getParams().getBool("getdefaults"))){
if(req.getParams().getBool("getdefaults", false)){
NamedList def = (NamedList) initArgs.get(PluginInfo.DEFAULTS);
rsp.add("getdefaults", def);
}
if(Boolean.TRUE.equals( req.getParams().getBool("initArgs"))) rsp.add("initArgs", initArgs);
if(req.getParams().getBool("initArgs", false)) {
rsp.add("initArgs", initArgs);
}
// Write the streams...
if( req.getContentStreams() != null ) {

View File

@ -1431,7 +1431,7 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
sLen = params.get(LEN);
compress = params.get(COMPRESSION);
useChecksum = params.getBool(CHECKSUM, false);
indexGen = params.getLong(GENERATION, null);
indexGen = params.getLong(GENERATION);
if (useChecksum) {
checksum = new Adler32();
}

View File

@ -47,8 +47,7 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter {
@Override
public void write(OutputStream out, SolrQueryRequest req, SolrQueryResponse response) throws IOException {
Resolver resolver = new Resolver(req, response.getReturnFields());
Boolean omitHeader = req.getParams().getBool(CommonParams.OMIT_HEADER);
if (omitHeader != null && omitHeader) response.removeResponseHeader();
if (req.getParams().getBool(CommonParams.OMIT_HEADER, false)) response.removeResponseHeader();
new JavaBinCodec(resolver).setWritableDocFields(resolver).marshal(response.getValues(), out);
}

View File

@ -92,8 +92,7 @@ class JSONWriter extends TextResponseWriter {
if(wrapperFunction!=null) {
writer.write(wrapperFunction + "(");
}
Boolean omitHeader = req.getParams().getBool(CommonParams.OMIT_HEADER);
if(omitHeader != null && omitHeader) rsp.removeResponseHeader();
if(req.getParams().getBool(CommonParams.OMIT_HEADER, false)) rsp.removeResponseHeader();
writeNamedList(null, rsp.getValues());
if(wrapperFunction!=null) {
writer.write(')');

View File

@ -66,8 +66,8 @@ public class HashQParserPlugin extends QParserPlugin {
}
public Query parse() {
int workers = localParams.getInt("workers");
int worker = localParams.getInt("worker");
int workers = localParams.getInt("workers", 0);
int worker = localParams.getInt("worker", 0);
String keys = params.get("partitionKeys");
keys = keys.replace(" ", "");
return new HashQuery(keys, workers, worker);

View File

@ -74,7 +74,7 @@ public class TextLogisticRegressionQParserPlugin extends QParserPlugin {
String[] terms = params.get("terms").split(",");
String ws = params.get("weights");
String dfsStr = params.get("idfs");
int iteration = params.getInt("iteration");
int iteration = params.getInt("iteration", 0);
String outcome = params.get("outcome");
int positiveLabel = params.getInt("positiveLabel", 1);
double threshold = params.getDouble("threshold", 0.5);

View File

@ -69,29 +69,16 @@ public class CloudMLTQParser extends QParser {
Map<String,Float> boostFields = new HashMap<>();
MoreLikeThis mlt = new MoreLikeThis(req.getSearcher().getIndexReader());
if(localParams.getInt("mintf") != null)
mlt.setMinTermFreq(localParams.getInt("mintf"));
mlt.setMinDocFreq(localParams.getInt("mindf", 0));
if(localParams.get("minwl") != null)
mlt.setMinWordLen(localParams.getInt("minwl"));
if(localParams.get("maxwl") != null)
mlt.setMaxWordLen(localParams.getInt("maxwl"));
if(localParams.get("maxqt") != null)
mlt.setMaxQueryTerms(localParams.getInt("maxqt"));
if(localParams.get("maxntp") != null)
mlt.setMaxNumTokensParsed(localParams.getInt("maxntp"));
if(localParams.get("maxdf") != null) {
mlt.setMaxDocFreq(localParams.getInt("maxdf"));
}
mlt.setMinTermFreq(localParams.getInt("mintf", MoreLikeThis.DEFAULT_MIN_TERM_FREQ));
mlt.setMinDocFreq(localParams.getInt("mindf", MoreLikeThis.DEFAULT_MIN_DOC_FREQ));
mlt.setMinWordLen(localParams.getInt("minwl", MoreLikeThis.DEFAULT_MIN_WORD_LENGTH));
mlt.setMaxWordLen(localParams.getInt("maxwl", MoreLikeThis.DEFAULT_MIN_WORD_LENGTH));
mlt.setMaxQueryTerms(localParams.getInt("maxqt",MoreLikeThis.DEFAULT_MAX_QUERY_TERMS));
mlt.setMaxNumTokensParsed(localParams.getInt("maxntp",MoreLikeThis.DEFAULT_MAX_NUM_TOKENS_PARSED));
mlt.setMaxDocFreq(localParams.getInt("maxdf", MoreLikeThis.DEFAULT_MAX_DOC_FREQ));
if(localParams.get("boost") != null) {
mlt.setBoost(localParams.getBool("boost"));
mlt.setBoost(localParams.getBool("boost", false));
boostFields = SolrPluginUtils.parseFieldBoosts(qf);
}

View File

@ -69,30 +69,17 @@ public class SimpleMLTQParser extends QParser {
ScoreDoc[] scoreDocs = td.scoreDocs;
MoreLikeThis mlt = new MoreLikeThis(req.getSearcher().getIndexReader());
if(localParams.getInt("mintf") != null)
mlt.setMinTermFreq(localParams.getInt("mintf"));
if(localParams.getInt("mindf") != null)
mlt.setMinDocFreq(localParams.getInt("mindf"));
if(localParams.get("minwl") != null)
mlt.setMinWordLen(localParams.getInt("minwl"));
if(localParams.get("maxwl") != null)
mlt.setMaxWordLen(localParams.getInt("maxwl"));
if(localParams.get("maxqt") != null)
mlt.setMaxQueryTerms(localParams.getInt("maxqt"));
if(localParams.get("maxntp") != null)
mlt.setMaxNumTokensParsed(localParams.getInt("maxntp"));
if(localParams.get("maxdf") != null) {
mlt.setMaxDocFreq(localParams.getInt("maxdf"));
}
mlt.setMinTermFreq(localParams.getInt("mintf", MoreLikeThis.DEFAULT_MIN_TERM_FREQ));
mlt.setMinDocFreq(localParams.getInt("mindf", MoreLikeThis.DEFAULT_MIN_DOC_FREQ));
mlt.setMinWordLen(localParams.getInt("minwl", MoreLikeThis.DEFAULT_MIN_WORD_LENGTH));
mlt.setMaxWordLen(localParams.getInt("maxwl", MoreLikeThis.DEFAULT_MAX_WORD_LENGTH));
mlt.setMaxQueryTerms(localParams.getInt("maxqt", MoreLikeThis.DEFAULT_MAX_QUERY_TERMS));
mlt.setMaxNumTokensParsed(localParams.getInt("maxntp", MoreLikeThis.DEFAULT_MAX_NUM_TOKENS_PARSED));
mlt.setMaxDocFreq(localParams.getInt("maxdf", MoreLikeThis.DEFAULT_MAX_DOC_FREQ));
// what happens if value is explicitly set to false?
if(localParams.get("boost") != null) {
mlt.setBoost(localParams.getBool("boost"));
mlt.setBoost(localParams.getBool("boost", false));
boostFields = SolrPluginUtils.parseFieldBoosts(qf);
}

View File

@ -92,11 +92,24 @@ public abstract class SolrParams implements Serializable, MapSerializable {
return val!=null ? val : getParams(param);
}
/** Returns the Boolean value of the param, or null if not set */
/**
* Returns the Boolean value of the param, or null if not set.
* Use this method only when you want to be explicit
* about absence of a value (<code>null</code>) vs the default value <code>false</code>.
* @see #getBool(String, boolean)
* @see #getPrimitiveBool(String)
*
**/
public Boolean getBool(String param) {
String val = get(param);
return val==null ? null : StrUtils.parseBool(val);
}
/** Returns the boolean value of the param, or <code>false</code> if not set */
public boolean getPrimitiveBool(String param) {
return getBool(param, false);
}
/** Returns the boolean value of the param, or def if not set */
public boolean getBool(String param, boolean def) {
@ -104,21 +117,46 @@ public abstract class SolrParams implements Serializable, MapSerializable {
return val==null ? def : StrUtils.parseBool(val);
}
/** Returns the Boolean value of the field param,
or the value for param, or null if neither is set. */
/**
* Returns the Boolean value of the field param,
* or the value for param, or null if neither is set.
* Use this method only when you want to be explicit
* about absence of a value (<code>null</code>) vs the default value <code>false</code>.
* @see #getFieldBool(String, String, boolean)
* @see #getPrimitiveFieldBool(String, String)
**/
public Boolean getFieldBool(String field, String param) {
String val = getFieldParam(field, param);
return val==null ? null : StrUtils.parseBool(val);
}
/**
* Returns the boolean value of the field param, or
* the value for param or
* the default value of boolean - <code>false</code>
*/
public boolean getPrimitiveFieldBool(String field, String param) {
return getFieldBool(field, param, false);
}
/** Returns the boolean value of the field param,
or the value for param, or def if neither is set. */
/**
* Returns the boolean value of the field param,
* or the value for param, or def if neither is set.
*
* */
public boolean getFieldBool(String field, String param, boolean def) {
String val = getFieldParam(field, param);
return val==null ? def : StrUtils.parseBool(val);
}
/** Returns the Integer value of the param, or null if not set */
/**
* Returns the Integer value of the param, or null if not set
* Use this method only when you want to be explicit
* about absence of a value (<code>null</code>) vs the default value for int -
* zero (<code>0</code>).
* @see #getInt(String, int)
* @see #getPrimitiveInt(String)
* */
public Integer getInt(String param) {
String val = get(param);
try {
@ -128,30 +166,33 @@ public abstract class SolrParams implements Serializable, MapSerializable {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, ex.getMessage(), ex );
}
}
/** Returns the Long value of the param, or null if not set */
public Long getLong(String param, Long def) {
String val = get(param);
try {
return val== null ? def : Long.parseLong(val);
}
catch( Exception ex ) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, ex.getMessage(), ex );
}
/**
* Returns int value of the the param or
* default value for int - zero (<code>0</code>) if not set.
*/
public int getPrimitiveInt(String param) {
return getInt(param, 0);
}
/** Returns the int value of the param, or def if not set */
public int getInt(String param, int def) {
String val = get(param);
try {
return val==null ? def : Integer.parseInt(val);
return val == null ? def : Integer.parseInt(val);
}
catch( Exception ex ) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, ex.getMessage(), ex );
}
}
/** Returns the Long value of the param, or null if not set */
/**
* Returns the Long value of the param, or null if not set
* Use this method only when you want to be explicit
* about absence of a value (<code>null</code>) vs the default value zero (<code>0</code>).
* @see #getLong(String, long)
*
**/
public Long getLong(String param) {
String val = get(param);
try {
@ -173,8 +214,13 @@ public abstract class SolrParams implements Serializable, MapSerializable {
/**
* Use this method only when you want to be explicit
* about absence of a value (<code>null</code>) vs the default value zero (<code>0</code>).
*
* @return The int value of the field param, or the value for param
* or <code>null</code> if neither is set.
*
* @see #getFieldInt(String, String, int)
**/
public Integer getFieldInt(String field, String param) {
String val = getFieldParam(field, param);
@ -199,7 +245,12 @@ public abstract class SolrParams implements Serializable, MapSerializable {
}
/** Returns the Float value of the param, or null if not set */
/**
* Returns the Float value of the param, or null if not set
* Use this method only when you want to be explicit
* about absence of a value (<code>null</code>) vs the default value zero (<code>0.0f</code>).
* @see #getFloat(String, float)
**/
public Float getFloat(String param) {
String val = get(param);
try {
@ -221,7 +272,13 @@ public abstract class SolrParams implements Serializable, MapSerializable {
}
}
/** Returns the Float value of the param, or null if not set */
/**
* Returns the Float value of the param, or null if not set
* Use this method only when you want to be explicit
* about absence of a value (<code>null</code>) vs the default value zero (<code>0.0d</code>).
* @see #getDouble(String, double)
*
**/
public Double getDouble(String param) {
String val = get(param);
try {
@ -244,7 +301,15 @@ public abstract class SolrParams implements Serializable, MapSerializable {
}
/** Returns the float value of the field param. */
/**
* Returns the float value of the field param.
* Use this method only when you want to be explicit
* about absence of a value (<code>null</code>) vs the default value zero (<code>0.0f</code>).
*
* @see #getFieldFloat(String, String, float)
* @see #getPrimitiveFieldFloat(String, String)
*
**/
public Float getFieldFloat(String field, String param) {
String val = getFieldParam(field, param);
try {
@ -254,6 +319,15 @@ public abstract class SolrParams implements Serializable, MapSerializable {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, ex.getMessage(), ex );
}
}
/**
* Returns the float value of the field param or
* the value for param or
* the default value for float - zero (<code>0.0f</code>)
*/
public float getPrimitiveFieldFloat(String field, String param) {
return getFieldFloat(field, param, 0.0f);
}
/** Returns the float value of the field param,
or the value for param, or def if neither is set. */
@ -267,7 +341,13 @@ public abstract class SolrParams implements Serializable, MapSerializable {
}
}
/** Returns the float value of the field param. */
/**
* Returns the float value of the field param.
* Use this method only when you want to be explicit
* about absence of a value (<code>null</code>) vs the default value zero (<code>0.0d</code>).
* @see #getDouble(String, double)
*
**/
public Double getFieldDouble(String field, String param) {
String val = getFieldParam(field, param);
try {