Author: hossman
Date: Tue Sep 12 15:50:06 2006
New Revision: 442747
URL: http://svn.apache.org/viewvc?view=rev&rev=442747
Log:
SOLR-46 - support for appended and invariant SolrParams in solrconfig.xml
Added:
incubator/solr/trunk/src/java/org/apache/solr/request/AppendedSolrParams.java
Modified:
incubator/solr/trunk/CHANGES.txt
incubator/solr/trunk/example/solr/conf/solrconfig.xml
incubator/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java
incubator/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java
incubator/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java
incubator/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java
Modified: incubator/solr/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/solr/trunk/CHANGES.txt?view=diff&rev=442747&r1=442746&r2=442747
==============================================================================
--- incubator/solr/trunk/CHANGES.txt (original)
+++ incubator/solr/trunk/CHANGES.txt Tue Sep 12 15:50:06 2006
@@ -49,6 +49,10 @@
24. Simple faceted search support for fields (enumerating terms)
and arbitrary queries added to both StandardRequestHandler and
DisMaxRequestHandler. (hossman, SOLR-44)
+25. In addition to specifying default RequestHandler params in the
+ solrconfig.xml, support has been added for configuring values to be
+ appended to the multi-val request params, as well as for configuring
+ invariant params that can not overridden in the query. (hossman, SOLR-46)
Changes in runtime behavior
1. classes reorganized into different packages, package names changed to
Apache
Modified: incubator/solr/trunk/example/solr/conf/solrconfig.xml
URL:
http://svn.apache.org/viewvc/incubator/solr/trunk/example/solr/conf/solrconfig.xml?view=diff&rev=442747&r1=442746&r2=442747
==============================================================================
--- incubator/solr/trunk/example/solr/conf/solrconfig.xml (original)
+++ incubator/solr/trunk/example/solr/conf/solrconfig.xml Tue Sep 12 15:50:06
2006
@@ -216,6 +216,51 @@
<!-- Note how you can register the same handler multiple times with
different names (and different init parameters)
-->
+ <requestHandler name="partitioned" class="solr.DisMaxRequestHandler" >
+ <lst name="defaults">
+ <str name="qf">text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0</str>
+ <str name="mm">2<-1 5<-2 6<90%</str>
+ </lst>
+ <!-- In addition to defaults, "appends" params can be specified
+ to identify values which should be appended to the list of
+ multi-val params from the query (or the existing "defaults").
+
+ In this example, the param "fq=instock:true" will be appended to
+ any query time fq params the user may specify, as a mechanism for
+ partitioning the index, independent of any user selected filtering
+ that may also be desired (perhaps as a result of faceted searching).
+
+ NOTE: there is *absolutely* nothing a client can do to prevent these
+ "appends" values from being used, so don't use this mechanism
+ unless you are sure you always want it.
+ -->
+ <lst name="appends">
+ <str name="fq">inStock:true</str>
+ </lst>
+ <!-- "invariants" are a way of letting the Solr maintainer lock down
+ the options available to Solr clients. Any params values
+ specified here are used regardless of what values may be specified
+ in either the query, the "defaults", or the "appends" params.
+
+ In this example, the facet.field and facet.query params are fixed,
+ limiting the facets clients can use. Faceting is not turned on by
+ default - but if the client does specify facet=true in the request,
+ these are the only facets they will be able to see counts for;
+ regardless of what other facet.field or facet.query params they
+ may specify.
+
+ NOTE: there is *absolutely* nothing a client can do to prevent these
+ "invariants" values from being used, so don't use this mechanism
+ unless you are sure you always want it.
+ -->
+ <lst name="invariants">
+ <str name="facet.field">cat</str>
+ <str name="facet.field">manu_exact</str>
+ <str name="facet.query">price:[* TO 500]</str>
+ <str name="facet.query">price:[500 TO *]</str>
+ </lst>
+ </requestHandler>
+
<requestHandler name="instock" class="solr.DisMaxRequestHandler" >
<!-- for legacy reasons, DisMaxRequestHandler will assume all init
params are "defaults" if you don't explicitly specify any defaults.
Added:
incubator/solr/trunk/src/java/org/apache/solr/request/AppendedSolrParams.java
URL:
http://svn.apache.org/viewvc/incubator/solr/trunk/src/java/org/apache/solr/request/AppendedSolrParams.java?view=auto&rev=442747
==============================================================================
---
incubator/solr/trunk/src/java/org/apache/solr/request/AppendedSolrParams.java
(added)
+++
incubator/solr/trunk/src/java/org/apache/solr/request/AppendedSolrParams.java
Tue Sep 12 15:50:06 2006
@@ -0,0 +1,47 @@
+/**
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.request;
+
+/**
+ * SolrParams wrapper which acts similar to DefaultSolrParams except that
+ * it "appends" the values of multi-value params from both sub instances, so
+ * that all of the values are returned.
+ */
+public class AppendedSolrParams extends DefaultSolrParams {
+ public AppendedSolrParams(SolrParams main, SolrParams extra) {
+ super(main, extra);
+ }
+
+ public String[] getParams(String param) {
+ String[] main = params.getParams(param);
+ String[] extra = defaults.getParams(param);
+ if (null == extra || 0 == extra.length) {
+ return main;
+ }
+ if (null == main || 0 == main.length) {
+ return extra;
+ }
+ String[] result = new String[main.length + extra.length];
+ System.arraycopy(main,0,result,0,main.length);
+ System.arraycopy(extra,0,result,main.length,extra.length);
+ return result;
+ }
+
+ public String toString() {
+ return "{main("+params+"),extra("+defaults+")}";
+ }
+}
Modified:
incubator/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java
URL:
http://svn.apache.org/viewvc/incubator/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java?view=diff&rev=442747&r1=442746&r2=442747
==============================================================================
---
incubator/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java
(original)
+++
incubator/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java
Tue Sep 12 15:50:06 2006
@@ -140,6 +140,8 @@
long numErrors;
SolrParams defaults;
+ SolrParams appends;
+ SolrParams invariants;
/** shorten the class referneces for utilities */
private static class U extends SolrPluginUtils {
@@ -206,6 +208,14 @@
if (o != null && o instanceof NamedList) {
defaults = SolrParams.toSolrParams((NamedList)o);
}
+ o = args.get("appends");
+ if (o != null && o instanceof NamedList) {
+ appends = SolrParams.toSolrParams((NamedList)o);
+ }
+ o = args.get("invariants");
+ if (o != null && o instanceof NamedList) {
+ invariants = SolrParams.toSolrParams((NamedList)o);
+ }
}
}
@@ -213,7 +223,7 @@
numRequests++;
try {
- U.setDefaults(req,defaults);
+ U.setDefaults(req,defaults,appends,invariants);
SolrParams params = req.getParams();
int flags = 0;
Modified:
incubator/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java
URL:
http://svn.apache.org/viewvc/incubator/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java?view=diff&rev=442747&r1=442746&r2=442747
==============================================================================
---
incubator/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java
(original)
+++
incubator/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java
Tue Sep 12 15:50:06 2006
@@ -60,6 +60,8 @@
long numRequests;
long numErrors;
SolrParams defaults;
+ SolrParams appends;
+ SolrParams invariants;
/** shorten the class references for utilities */
private static class U extends SolrPluginUtils {
@@ -71,13 +73,22 @@
if (o != null && o instanceof NamedList) {
defaults = SolrParams.toSolrParams((NamedList)o);
}
+ o = args.get("appends");
+ if (o != null && o instanceof NamedList) {
+ appends = SolrParams.toSolrParams((NamedList)o);
+ }
+ o = args.get("invariants");
+ if (o != null && o instanceof NamedList) {
+ invariants = SolrParams.toSolrParams((NamedList)o);
+ }
+
}
public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {
numRequests++;
try {
- U.setDefaults(req,defaults);
+ U.setDefaults(req,defaults,appends,invariants);
SolrParams p = req.getParams();
String sreq = p.get(Q);
Modified:
incubator/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java
URL:
http://svn.apache.org/viewvc/incubator/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java?view=diff&rev=442747&r1=442746&r2=442747
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java
(original)
+++ incubator/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java Tue
Sep 12 15:50:06 2006
@@ -32,6 +32,7 @@
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryResponse;
import org.apache.solr.request.DefaultSolrParams;
+import org.apache.solr.request.AppendedSolrParams;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.search.*;
@@ -56,14 +57,41 @@
*/
public class SolrPluginUtils {
- /** set defaults on a SolrQueryRequest */
+ /**
+ * Set defaults on a SolrQueryRequest.
+ *
+ * RequestHandlers can use this method to ensure their defaults are
+ * visible to other components such as the response writer
+ */
public static void setDefaults(SolrQueryRequest req, SolrParams defaults) {
+ setDefaults(req, defaults, null, null);
+ }
+
+ /**
+ * Set default-ish params on a SolrQueryRequest.
+ *
+ * RequestHandlers can use this method to ensure their defaults and
+ * overrides are visible to other components such as the response writer
+ *
+ * @param req The request whose params we are interested i
+ * @param defaults values to be used if no values are specified in the
request params
+ * @param appends values to be appended to those from the request (or
defaults) when dealing with multi-val params, or treated as another layer of
defaults for singl-val params.
+ * @param invariants values which will be used instead of any request, or
default values, regardless of context.
+ */
+ public static void setDefaults(SolrQueryRequest req, SolrParams defaults,
+ SolrParams appends, SolrParams invariants) {
+
SolrParams p = req.getParams();
if (defaults != null) {
p = new DefaultSolrParams(p,defaults);
- // set params so they will be visible to other components such as the
response writer
- req.setParams(p);
}
+ if (appends != null) {
+ p = new AppendedSolrParams(p,appends);
+ }
+ if (invariants != null) {
+ p = new DefaultSolrParams(invariants,p);
+ }
+ req.setParams(p);
}
Modified:
incubator/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java
URL:
http://svn.apache.org/viewvc/incubator/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java?view=diff&rev=442747&r1=442746&r2=442747
==============================================================================
--- incubator/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java
(original)
+++ incubator/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java
Tue Sep 12 15:50:06 2006
@@ -284,6 +284,22 @@
assertEquals(p.getBool("foo",true), true);
assertEquals(p.getBool("foo",false), false);
assertEquals(!!p.getBool("bt"), !p.getBool("bf"));
+
+ NamedList more = new NamedList();
+ more.add("s", "aaa");
+ more.add("s", "ccc");
+ more.add("ss","YYY");
+ more.add("xx","XXX");
+ p = new AppendedSolrParams(p, SolrParams.toSolrParams(more));
+ assertEquals(3, p.getParams("s").length);
+ assertEquals("bbb", p.getParams("s")[0]);
+ assertEquals("aaa", p.getParams("s")[1]);
+ assertEquals("ccc", p.getParams("s")[2]);
+ assertEquals(3, p.getParams("s").length);
+ assertEquals("SSS", p.get("ss"));
+ assertEquals("XXX", p.get("xx"));
+
+
}