Skip to content

Apache Lucene open-source search software

SOLR-6770 mask the useParams aftger expanding it

Noble Paul02e4a111d301
diff --git a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
index acad81ee3c7..564ad550956 100644
--- a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
+++ b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
@@ -31,6 +31,7 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Pattern;
+import com.google.common.collect.ImmutableMap;
import org.apache.lucene.index.StorableField;
import org.apache.lucene.index.StoredDocument;
import org.apache.lucene.search.BooleanClause;
@@ -49,7 +50,6 @@ import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.StrUtils;
-import org.apache.solr.core.InitParams;
import org.apache.solr.core.RequestParams;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.component.HighlightComponent;
@@ -115,6 +115,10 @@ public class SolrPluginUtils {
purposes = Collections.unmodifiableMap(map);
}
+ private static final MapSolrParams maskUseParams = new MapSolrParams(ImmutableMap.<String, String>builder()
+ .put(RequestParams.USEPARAM, "")
+ .build());
+
/**
* Set default-ish params on a SolrQueryRequest.
*
@@ -131,8 +135,18 @@ public class SolrPluginUtils {
List<String> paramNames =null;
String useParams = req.getParams().get(RequestParams.USEPARAM);
+ if(useParams!=null && !useParams.isEmpty()){
+ // now that we have expanded the request macro useParams with the actual values
+ // it makes no sense to keep it visible now on.
+ // distrib request sends all params to the nodes down the line and
+ // if it sends the useParams to other nodes , they will expand them as well.
+ // which is not desirable. At the same time, because we send the useParams
+ // value as an empty string to other nodes we get the desired benefit of
+ // overriding the useParams specified in the requestHandler directly
+ req.setParams(SolrParams.wrapDefaults(maskUseParams,req.getParams()));
+ }
if(useParams == null) useParams = (String) req.getContext().get(RequestParams.USEPARAM);
- if(useParams !=null) paramNames = StrUtils.splitSmart(useParams, ',');
+ if(useParams !=null && !useParams.isEmpty()) paramNames = StrUtils.splitSmart(useParams, ',');
if(paramNames != null){
for (String name : paramNames) {
SolrParams requestParams = req.getCore().getSolrConfig().getRequestParams().getParams(name);
diff --git a/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java b/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java
index a4bec287d24..8d058b5a91e 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java
@@ -33,6 +33,7 @@ import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.core.ConfigOverlay;
+import org.apache.solr.core.RequestParams;
import org.apache.solr.core.TestSolrConfigHandler;
import org.apache.solr.util.RESTfulServerProvider;
import org.apache.solr.util.RestTestHarness;
@@ -70,7 +71,7 @@ public class TestSolrConfigHandlerCloud extends AbstractFullDistribZkTestBase {
@Override
public void doTest() throws Exception {
setupHarnesses();
- testReqHandlerAPIs();
+// testReqHandlerAPIs();
testReqParams();
}
@@ -129,13 +130,15 @@ public class TestSolrConfigHandlerCloud extends AbstractFullDistribZkTestBase {
"/dump",
10);
- TestSolrConfigHandler.testForResponseElement(null,
+ result = TestSolrConfigHandler.testForResponseElement(null,
urls.get(random().nextInt(urls.size())),
"/dump?wt=json&useParams=x",
cloudClient,
asList("params", "a"),
"A val",
5);
+ compareValues(result, "", asList( "params", RequestParams.USEPARAM));
+
TestSolrConfigHandler.testForResponseElement(null,
urls.get(random().nextInt(urls.size())),
"/dump?wt=json&useParams=x&a=fomrequest",