mirror of https://github.com/apache/lucene.git
SOLR-6365 <paramSet> renamed to <initParams>
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1626045 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1bf9802293
commit
f16af7afc0
|
@ -26,16 +26,16 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
/**
|
||||
* An Object which represents a paramSet tag
|
||||
* An Object which represents a <args> tag
|
||||
*
|
||||
*/
|
||||
public class ParamSet {
|
||||
public static final String TYPE = "paramSet";
|
||||
public class InitParams {
|
||||
public static final String TYPE = "initParams";
|
||||
public final String name;
|
||||
public final Set<String> paths;
|
||||
public final NamedList defaults,invariants,appends;
|
||||
|
||||
public ParamSet(PluginInfo p) {
|
||||
public InitParams(PluginInfo p) {
|
||||
this.name = p.attributes.get("name");
|
||||
Set<String> paths = null;
|
||||
String pathStr = p.attributes.get("path");
|
|
@ -22,7 +22,6 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -199,21 +198,21 @@ public final class RequestHandlers {
|
|||
}
|
||||
|
||||
private PluginInfo applyParamSet(SolrConfig config, PluginInfo info) {
|
||||
List<ParamSet> paramSets= new ArrayList<>();
|
||||
String p = info.attributes.get("paramSet");
|
||||
List<InitParams> ags = new ArrayList<>();
|
||||
String p = info.attributes.get(InitParams.TYPE);
|
||||
if(p!=null) {
|
||||
for (String paramSet : StrUtils.splitSmart(p, ',')) {
|
||||
if(config.getParamSets().containsKey(paramSet)) paramSets.add(config.getParamSets().get(paramSet));
|
||||
else log.warn("INVALID paramSet {} in requestHandler {}", paramSet, info.toString());
|
||||
for (String arg : StrUtils.splitSmart(p, ',')) {
|
||||
if(config.getInitParams().containsKey(arg)) ags.add(config.getInitParams().get(arg));
|
||||
else log.warn("INVALID paramSet {} in requestHandler {}", arg, info.toString());
|
||||
}
|
||||
}
|
||||
for (ParamSet paramSet : config.getParamSets().values()) {
|
||||
if(paramSet.matchPath(info.name)) paramSets.add(paramSet);
|
||||
for (InitParams args : config.getInitParams().values()) {
|
||||
if(args.matchPath(info.name)) ags.add(args);
|
||||
}
|
||||
if(!paramSets.isEmpty()){
|
||||
if(!ags.isEmpty()){
|
||||
info = new PluginInfo(info.type, info.attributes, info.initArgs.clone(), info.children);
|
||||
for (ParamSet paramSet : paramSets) {
|
||||
paramSet.apply(info.initArgs);
|
||||
for (InitParams args : ags) {
|
||||
args.apply(info.initArgs);
|
||||
}
|
||||
}
|
||||
return info;
|
||||
|
|
|
@ -23,8 +23,6 @@ import org.apache.lucene.search.BooleanQuery;
|
|||
import org.apache.lucene.util.Version;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.SolrException.ErrorCode;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.common.util.StrUtils;
|
||||
import org.apache.solr.handler.component.SearchComponent;
|
||||
import org.apache.solr.request.SolrRequestHandler;
|
||||
import org.apache.solr.response.QueryResponseWriter;
|
||||
|
@ -59,13 +57,10 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -312,24 +307,24 @@ public class SolrConfig extends Config {
|
|||
addHttpRequestToContext = getBool(
|
||||
"requestDispatcher/requestParsers/@addHttpRequestToContext", false );
|
||||
|
||||
loadPluginInfo(ParamSet.class,ParamSet.TYPE, MULTI_OK);
|
||||
List<PluginInfo> paramSetInfos = pluginStore.get(ParamSet.class.getName()) ;
|
||||
if(paramSetInfos!=null){
|
||||
Map<String,ParamSet> paramSets = new HashMap<>();
|
||||
for (PluginInfo p : paramSetInfos) {
|
||||
ParamSet paramSet = new ParamSet(p);
|
||||
paramSets.put(paramSet.name == null ? String.valueOf(paramSet.hashCode()) : paramSet.name , paramSet );
|
||||
loadPluginInfo(InitParams.class, InitParams.TYPE, MULTI_OK);
|
||||
List<PluginInfo> argsInfos = pluginStore.get(InitParams.class.getName()) ;
|
||||
if(argsInfos!=null){
|
||||
Map<String,InitParams> argsMap = new HashMap<>();
|
||||
for (PluginInfo p : argsInfos) {
|
||||
InitParams args = new InitParams(p);
|
||||
argsMap.put(args.name == null ? String.valueOf(args.hashCode()) : args.name, args);
|
||||
}
|
||||
this.paramSets = Collections.unmodifiableMap(paramSets);
|
||||
this.initParams = Collections.unmodifiableMap(argsMap);
|
||||
|
||||
}
|
||||
|
||||
solrRequestParsers = new SolrRequestParsers(this);
|
||||
Config.log.info("Loaded SolrConfig: " + name);
|
||||
}
|
||||
private Map<String,ParamSet> paramSets = Collections.emptyMap();
|
||||
public Map<String, ParamSet> getParamSets() {
|
||||
return paramSets;
|
||||
private Map<String,InitParams> initParams = Collections.emptyMap();
|
||||
public Map<String, InitParams> getInitParams() {
|
||||
return initParams;
|
||||
}
|
||||
protected UpdateHandlerInfo loadUpdatehandlerInfo() {
|
||||
return new UpdateHandlerInfo(get("updateHandler/@class",null),
|
||||
|
|
|
@ -48,7 +48,7 @@ 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.ParamSet;
|
||||
import org.apache.solr.core.InitParams;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
import org.apache.solr.handler.component.HighlightComponent;
|
||||
import org.apache.solr.handler.component.ResponseBuilder;
|
||||
|
@ -125,14 +125,14 @@ public class SolrPluginUtils {
|
|||
*/
|
||||
public static void setDefaults(SolrQueryRequest req, SolrParams defaults,
|
||||
SolrParams appends, SolrParams invariants) {
|
||||
String paramSetNames = req.getParams().get(ParamSet.TYPE);
|
||||
if(paramSetNames !=null){
|
||||
for (String name : StrUtils.splitSmart(paramSetNames,',')) {
|
||||
ParamSet paramSet = req.getCore().getSolrConfig().getParamSets().get(name);
|
||||
if(paramSet!=null){
|
||||
if(paramSet.defaults != null) defaults = SolrParams.wrapDefaults(SolrParams.toSolrParams(paramSet.defaults) , defaults);
|
||||
if(paramSet.invariants != null) invariants = SolrParams.wrapDefaults(invariants, SolrParams.toSolrParams(paramSet.invariants));
|
||||
if(paramSet.appends != null) appends = SolrParams.wrapAppended(appends, SolrParams.toSolrParams(paramSet.appends));
|
||||
String useParams = req.getParams().get("useParam");
|
||||
if(useParams !=null){
|
||||
for (String name : StrUtils.splitSmart(useParams,',')) {
|
||||
InitParams initParams = req.getCore().getSolrConfig().getInitParams().get(name);
|
||||
if(initParams !=null){
|
||||
if(initParams.defaults != null) defaults = SolrParams.wrapDefaults(SolrParams.toSolrParams(initParams.defaults) , defaults);
|
||||
if(initParams.invariants != null) invariants = SolrParams.wrapDefaults(invariants, SolrParams.toSolrParams(initParams.invariants));
|
||||
if(initParams.appends != null) appends = SolrParams.wrapAppended(appends, SolrParams.toSolrParams(initParams.appends));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.RAMDirectoryFactory}"/>
|
||||
<requestHandler name="standard" class="solr.StandardRequestHandler"/>
|
||||
<requestHandler name="/update" class="solr.UpdateRequestHandler"/>
|
||||
<paramSet name="a" path="/dump3,/dump6,/root/*,/root1/**">
|
||||
<initParams name="a" path="/dump3,/dump6,/root/*,/root1/**">
|
||||
<lst name="defaults">
|
||||
<str name="a">A</str>
|
||||
</lst>
|
||||
|
@ -36,19 +36,19 @@
|
|||
<lst name="appends">
|
||||
<str name="c">C</str>
|
||||
</lst>
|
||||
</paramSet>
|
||||
<paramSet path="/dump6">
|
||||
</initParams>
|
||||
<initParams path="/dump6">
|
||||
<lst name="defaults">
|
||||
<str name="p">P</str>
|
||||
</lst>
|
||||
</paramSet>
|
||||
</initParams>
|
||||
<requestHandler name="/dump3" class="DumpRequestHandler"/>
|
||||
<requestHandler name="/dump6" class="DumpRequestHandler"/>
|
||||
<requestHandler name="/dump4" class="DumpRequestHandler"/>
|
||||
<requestHandler name="/root/dump5" class="DumpRequestHandler"/>
|
||||
<requestHandler name="/root1/anotherlevel/dump6" class="DumpRequestHandler"/>
|
||||
<requestHandler name="/dump1" class="DumpRequestHandler" paramSet="a"/>
|
||||
<requestHandler name="/dump2" class="DumpRequestHandler" paramSet="a">
|
||||
<requestHandler name="/dump1" class="DumpRequestHandler" initParams="a"/>
|
||||
<requestHandler name="/dump2" class="DumpRequestHandler" initParams="a">
|
||||
<lst name="defaults">
|
||||
<str name="a">A1</str>
|
||||
</lst>
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.junit.Test;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TestParamSet extends SolrTestCaseJ4 {
|
||||
public class TestInitParams extends SolrTestCaseJ4 {
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
initCore("solrconfig-paramset.xml","schema.xml");
|
||||
|
@ -69,7 +69,7 @@ public class TestParamSet extends SolrTestCaseJ4 {
|
|||
for (String s : Arrays.asList("/dump4")) {
|
||||
SolrRequestHandler handler = h.getCore().getRequestHandler(s);
|
||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
||||
handler.handleRequest(req("param", "a","param","b" ,"param","c", "paramSet","a"), rsp);
|
||||
handler.handleRequest(req("param", "a","param","b" ,"param","c", "useParam","a"), rsp);
|
||||
NamedList def = (NamedList) rsp.getValues().get("params");
|
||||
assertEquals("A", def.get("a"));
|
||||
assertEquals("B", def.get("b"));
|
|
@ -969,17 +969,17 @@
|
|||
<str>spellcheck</str>
|
||||
</arr>
|
||||
</requestHandler>
|
||||
<paramSet path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
|
||||
<initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
|
||||
<lst name="defaults">
|
||||
<str name="df">_text</str>
|
||||
</lst>
|
||||
</paramSet>
|
||||
</initParams>
|
||||
|
||||
<paramSet path="/update/**">
|
||||
<initParams path="/update/**">
|
||||
<lst name="defaults">
|
||||
<str name="update.chain">add-unknown-fields-to-the-schema</str>
|
||||
</lst>
|
||||
</paramSet>
|
||||
</initParams>
|
||||
|
||||
<!-- Solr Cell Update Request Handler
|
||||
|
||||
|
|
|
@ -1052,11 +1052,11 @@
|
|||
-->
|
||||
<!--<requestHandler name="/update" class="solr.UpdateRequestHandler">
|
||||
</requestHandler>-->
|
||||
<paramSet path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
|
||||
<initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
|
||||
<lst name="defaults">
|
||||
<str name="df">text</str>
|
||||
</lst>
|
||||
</paramSet>
|
||||
</initParams>
|
||||
<!-- The following are implicitly added
|
||||
<requestHandler name="/update/json" class="solr.UpdateRequestHandler">
|
||||
<lst name="defaults">
|
||||
|
|
Loading…
Reference in New Issue