You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2016/10/21 13:28:49 UTC
lucene-solr:master: SOLR-9546: Eliminate unnecessary boxing/unboxing
going on in SolrParams
Repository: lucene-solr
Updated Branches:
refs/heads/master bc0116af6 -> ccbafdc40
SOLR-9546: Eliminate unnecessary boxing/unboxing going on in SolrParams
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/ccbafdc4
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/ccbafdc4
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/ccbafdc4
Branch: refs/heads/master
Commit: ccbafdc403fb66e4becfe1b934957f6247b07a7a
Parents: bc0116a
Author: Noble Paul <no...@apache.org>
Authored: Fri Oct 21 18:58:33 2016 +0530
Committer: Noble Paul <no...@apache.org>
Committed: Fri Oct 21 18:58:33 2016 +0530
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +
.../org/apache/solr/cloud/ZkController.java | 2 +-
.../apache/solr/handler/DumpRequestHandler.java | 6 +-
.../apache/solr/handler/ReplicationHandler.java | 2 +-
.../solr/response/BinaryResponseWriter.java | 3 +-
.../solr/response/JSONResponseWriter.java | 3 +-
.../apache/solr/search/HashQParserPlugin.java | 4 +-
.../TextLogisticRegressionQParserPlugin.java | 2 +-
.../apache/solr/search/mlt/CloudMLTQParser.java | 29 ++---
.../solr/search/mlt/SimpleMLTQParser.java | 33 ++---
.../apache/solr/common/params/SolrParams.java | 124 +++++++++++++++----
11 files changed, 133 insertions(+), 77 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccbafdc4/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index b4dcf4c..7228559 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -220,6 +220,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
----------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccbafdc4/solr/core/src/java/org/apache/solr/cloud/ZkController.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
index 9b0a90e..c0a8d55 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
@@ -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);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccbafdc4/solr/core/src/java/org/apache/solr/handler/DumpRequestHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/DumpRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/DumpRequestHandler.java
index 9b0f959..ecafb52 100644
--- a/solr/core/src/java/org/apache/solr/handler/DumpRequestHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/DumpRequestHandler.java
@@ -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 ) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccbafdc4/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
index 84e1ba2..08b6f39 100644
--- a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
@@ -1436,7 +1436,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();
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccbafdc4/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java b/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java
index 9634e63..11c6074 100644
--- a/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java
+++ b/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java
@@ -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);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccbafdc4/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java b/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java
index 522030f..cd6648b 100644
--- a/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java
+++ b/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java
@@ -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(')');
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccbafdc4/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java
index df493f0..3e0fc22 100644
--- a/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java
@@ -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);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccbafdc4/solr/core/src/java/org/apache/solr/search/TextLogisticRegressionQParserPlugin.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/TextLogisticRegressionQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/TextLogisticRegressionQParserPlugin.java
index e1d3b7b..c1b8906 100644
--- a/solr/core/src/java/org/apache/solr/search/TextLogisticRegressionQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/TextLogisticRegressionQParserPlugin.java
@@ -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);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccbafdc4/solr/core/src/java/org/apache/solr/search/mlt/CloudMLTQParser.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/mlt/CloudMLTQParser.java b/solr/core/src/java/org/apache/solr/search/mlt/CloudMLTQParser.java
index 0f85feb..9ff5a3c 100644
--- a/solr/core/src/java/org/apache/solr/search/mlt/CloudMLTQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/mlt/CloudMLTQParser.java
@@ -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);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccbafdc4/solr/core/src/java/org/apache/solr/search/mlt/SimpleMLTQParser.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/mlt/SimpleMLTQParser.java b/solr/core/src/java/org/apache/solr/search/mlt/SimpleMLTQParser.java
index da3a487..50803df 100644
--- a/solr/core/src/java/org/apache/solr/search/mlt/SimpleMLTQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/mlt/SimpleMLTQParser.java
@@ -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);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccbafdc4/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java b/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java
index 0b74c14..e884a5b 100644
--- a/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java
+++ b/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java
@@ -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 {