Apache Solr open-source search software
more progress on SOLR-43
Chris M. Hostetter74f787bede2f
diff --git a/CHANGES.txt b/CHANGES.txtindex f28aa04895b..87e21d6236d 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -55,6 +55,10 @@ Changes in runtime behavior4. Highlighter params changed to be prefixed with "hl."; allow fragmentsizecustomization and per-field overrides on many options(Andrew May via klaas, SOLR-37)+ 5. Default param values for DisMaxRequestHandler should now be specified+ using a '<lst name="defaults">...</lst>' init param, for backwards+ compatability all init prams will be used as defaults if an init param+ with that name does not exist. (hossman, SOLR-43)Optimizations1. getDocListAndSet can now generate both a DocList and a DocSet from adiff --git a/example/solr/conf/solrconfig.xml b/example/solr/conf/solrconfig.xmlindex fe2235d4df6..f63576fc965 100755--- a/example/solr/conf/solrconfig.xml+++ b/example/solr/conf/solrconfig.xml@@ -193,6 +193,7 @@its init() method.--><requestHandler name="dismax" class="solr.DisMaxRequestHandler" >+ <lst name="defaults"><float name="tie">0.01</float><str name="qf">text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4@@ -210,11 +211,15 @@2<-1 5<-2 6<90%</str><int name="ps">100</int>+ </lst></requestHandler><!-- Note how you can register the same handler multiple times withdifferent names (and different init parameters)--><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.+ --><str name="fq">inStock:true</str>diff --git a/src/java/org/apache/solr/request/DisMaxRequestHandler.java b/src/java/org/apache/solr/request/DisMaxRequestHandler.javaindex d3a4a1acd1d..da4868b3744 100644--- a/src/java/org/apache/solr/request/DisMaxRequestHandler.java+++ b/src/java/org/apache/solr/request/DisMaxRequestHandler.java@@ -35,6 +35,7 @@ import org.apache.solr.util.NamedList;import org.apache.solr.util.HighlightingUtils;import org.apache.solr.util.SolrPluginUtils;import org.apache.solr.util.DisMaxParams;+import static org.apache.solr.request.SolrParams.*;import org.apache.lucene.search.Query;import org.apache.lucene.search.BooleanQuery;@@ -110,6 +111,10 @@ import java.net.URL;* <li>sort - (Order By) list of fields and direction to sort on.* </li>* </ul>+ *+ * <pre>+ * :TODO: make bf,fq,pf,qf multival params now that SolrParams supports them+ * </pre>*/public class DisMaxRequestHandlerimplements SolrRequestHandler, SolrInfoMBean {@@ -127,14 +132,18 @@ public class DisMaxRequestHandler// acceptable every million requests or so?long numRequests;long numErrors;++ SolrParams defaults;/** shorten the class referneces for utilities */private static class U extends SolrPluginUtils {/* :NOOP */}+ /** shorten the class referneces for utilities */+ private static class DMP extends DisMaxParams {+ /* :NOOP */+ }- protected final DisMaxParams params = new DisMaxParams();-public DisMaxRequestHandler() {super();}@@ -182,28 +191,36 @@ public class DisMaxRequestHandler*/public void init(NamedList args) {- params.setValues(args);-+ if (-1 == args.indexOf("defaults",0)) {+ // no explict defaults list, use all args implicitly+ // indexOf so "<null name="defaults"/> is valid indicator of no defaults+ defaults = SolrParams.toSolrParams(args);+ } else {+ Object o = args.get("defaults");+ if (o != null && o instanceof NamedList) {+ defaults = SolrParams.toSolrParams((NamedList)o);+ }+ }}public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {numRequests++;try {-+ U.setDefaults(req,defaults);+ SolrParams params = req.getParams();+int flags = 0;+SolrIndexSearcher s = req.getSearcher();IndexSchema schema = req.getSchema();- Map<String,Float> queryFields =- U.parseFieldBoosts(U.getParam(req, params.QF, params.qf));- Map<String,Float> phraseFields =- U.parseFieldBoosts(U.getParam(req, params.PF, params.pf));+ Map<String,Float> queryFields = U.parseFieldBoosts(params.get(DMP.QF));+ Map<String,Float> phraseFields = U.parseFieldBoosts(params.get(DMP.PF));- float tiebreaker = U.getNumberParam- (req, params.TIE, params.tiebreaker).floatValue();+ float tiebreaker = params.getFloat(DMP.TIE, 0.0f);- int pslop = U.getNumberParam(req, params.PS, params.pslop).intValue();+ int pslop = params.getInt(DMP.PS, 0);/* a generic parser for parsing regular lucene queries */QueryParser p = new SolrQueryParser(schema, null);@@ -227,14 +244,14 @@ public class DisMaxRequestHandler/* * * Main User Query * * */String userQuery = U.partialEscape- (U.stripUnbalancedQuotes(req.getQueryString())).toString();+ (U.stripUnbalancedQuotes(params.get(Q))).toString();/* the main query we will execute. we disable the coord because* this query is an artificial construct*/BooleanQuery query = new BooleanQuery(true);- String minShouldMatch = U.getParam(req, params.MM, params.mm);+ String minShouldMatch = params.get(DMP.MM, "100%");Query dis = up.parse(userQuery);@@ -266,7 +283,7 @@ public class DisMaxRequestHandler/* * * Boosting Query * * */- String boostQuery = U.getParam(req, params.BQ, params.bq);+ String boostQuery = params.get(DMP.BQ);if (null != boostQuery && !boostQuery.equals("")) {Query tmp = p.parse(boostQuery);/* if the default boost was used, and we've got a BooleanQuery@@ -283,7 +300,7 @@ public class DisMaxRequestHandler/* * * Boosting Functions * * */- String boostFunc = U.getParam(req, params.BF, params.bf);+ String boostFunc = params.get(DMP.BF);if (null != boostFunc && !boostFunc.equals("")) {List<Query> funcs = U.parseFuncs(schema, boostFunc);for (Query f : funcs) {@@ -296,7 +313,7 @@ public class DisMaxRequestHandlerList<Query> restrictions = new ArrayList<Query>(1);/* User Restriction */- String filterQueryString = U.getParam(req, params.FQ, params.fq);+ String filterQueryString = params.get(DMP.FQ);Query filterQuery = null;if (null != filterQueryString && !filterQueryString.equals("")) {filterQuery = p.parse(filterQueryString);@@ -305,7 +322,7 @@ public class DisMaxRequestHandler/* * * Generate Main Results * * */- flags |= U.setReturnFields(U.getParam(req, SolrParams.FL, params.fl), rsp);+ flags |= U.setReturnFields(req,rsp);DocList results = s.getDocList(query, restrictions,SolrPluginUtils.getSort(req),req.getStart(), req.getLimit(),@@ -317,7 +334,7 @@ public class DisMaxRequestHandler/* * * Debugging Info * * */try {- NamedList debug = U.doStandardDebug(req, userQuery, query, results, params);+ NamedList debug = U.doStandardDebug(req, userQuery, query, results);if (null != debug) {debug.add("boostquery", boostQuery);debug.add("boostfunc", boostFunc);diff --git a/src/java/org/apache/solr/request/SolrParams.java b/src/java/org/apache/solr/request/SolrParams.javaindex 5d81932f814..4b923b3a4c0 100644--- a/src/java/org/apache/solr/request/SolrParams.java+++ b/src/java/org/apache/solr/request/SolrParams.java@@ -72,6 +72,12 @@ public abstract class SolrParams {public abstract String[] getParams(String param);+ /** returns the value of the param, or def if not set */+ public String get(String param, String def) {+ String val = get(param);+ return val==null ? def : val;+ }+protected String fpname(String field, String param) {return "f."+field+'.'+param;}diff --git a/src/java/org/apache/solr/util/DisMaxParams.java b/src/java/org/apache/solr/util/DisMaxParams.javaindex 1593f8ddebe..0b45b8cbdc2 100755--- a/src/java/org/apache/solr/util/DisMaxParams.java+++ b/src/java/org/apache/solr/util/DisMaxParams.java@@ -65,21 +65,45 @@ import java.io.IOException;/** query and init param for field list */public static String GEN = "gen";- /** the default tie breaker to use in DisjunctionMaxQueries */+ /**+ * the default tie breaker to use in DisjunctionMaxQueries+ * @deprecated - use explicit default with SolrParams.getFloat+ */public float tiebreaker = 0.0f;- /** the default query fields to be used */+ /**+ * the default query fields to be used+ * @deprecated - use explicit default with SolrParams.get+ */public String qf = null;- /** the default phrase boosting fields to be used */+ /**+ * the default phrase boosting fields to be used+ * @deprecated - use explicit default with SolrParams.get+ */public String pf = null;- /** the default min should match to be used */+ /**+ * the default min should match to be used+ * @deprecated - use explicit default with SolrParams.get+ */public String mm = "100%";- /** the default phrase slop to be used */+ /**+ * the default phrase slop to be used+ * @deprecated - use explicit default with SolrParams.getInt+ */public int pslop = 0;- /** the default boosting query to be used */+ /**+ * the default boosting query to be used+ * @deprecated - use explicit default with SolrParams.get+ */public String bq = null;- /** the default boosting functions to be used */+ /**+ * the default boosting functions to be used+ * @deprecated - use explicit default with SolrParams.get+ */public String bf = null;- /** the default filtering query to be used */+ /**+ * the default filtering query to be used+ * @deprecated - use explicit default with SolrParams.get+ */public String fq = null;@@ -96,7 +120,7 @@ import java.io.IOException;* If any param is not of in the NamedList, it is skipped and the* old value is left alone.* </p>- *+ * @deprecated use SolrParams.toSolrParams*/public void setValues(NamedList args) {diff --git a/src/java/org/apache/solr/util/SolrPluginUtils.java b/src/java/org/apache/solr/util/SolrPluginUtils.javaindex 332fe70b524..13c67b24348 100644--- a/src/java/org/apache/solr/util/SolrPluginUtils.java+++ b/src/java/org/apache/solr/util/SolrPluginUtils.java@@ -84,6 +84,7 @@ public class SolrPluginUtils {/*** Returns the param, or the default if it's empty or not specified.+ * @deprecated use SolrParam.get(String,String)*/public static String getParam(SolrQueryRequest req,String param, String def) {@@ -100,6 +101,7 @@ public class SolrPluginUtils {/*** Treats the param value as a Number, returns the default if nothing is* there or if it's not a number.+ * @deprecated use SolrParam.getFloat(String,float)*/public static Number getNumberParam(SolrQueryRequest req,String param, Number def) {@@ -120,6 +122,7 @@ public class SolrPluginUtils {/*** Treats parameter value as a boolean. The string 'false' is false;* any other non-empty string is true.+ * @deprecated use SolrParam.getBool(String,boolean)*/public static boolean getBooleanParam(SolrQueryRequest req,String param, boolean def) {@@ -208,6 +211,7 @@ public class SolrPluginUtils {* (and perhaps other clauses) that identifies the main* result set of the response.* @param results the main result set of the response+ * @deprecated Use doStandardDebug(SolrQueryRequest,String,Query,DocList) with setDefaults*/public static NamedList doStandardDebug(SolrQueryRequest req,String userQuery,diff --git a/src/test/org/apache/solr/DisMaxRequestHandlerTest.java b/src/test/org/apache/solr/DisMaxRequestHandlerTest.javaindex d16d772b5cb..74665104b44 100644--- a/src/test/org/apache/solr/DisMaxRequestHandlerTest.java+++ b/src/test/org/apache/solr/DisMaxRequestHandlerTest.java@@ -96,7 +96,12 @@ public class DisMaxRequestHandlerTest extends AbstractSolrTestCase {}-+ public void testOldStyleDefaults() throws Exception {++ lrf = h.getRequestFactory+ ("dismaxOldStyleDefaults",0,20,"version","2.0");+ testSomeStuff();+ }diff --git a/src/test/test-files/solr/conf/solrconfig.xml b/src/test/test-files/solr/conf/solrconfig.xmlindex 46f08b87a5f..62498ca595a 100644--- a/src/test/test-files/solr/conf/solrconfig.xml+++ b/src/test/test-files/solr/conf/solrconfig.xml@@ -168,7 +168,29 @@is not specified in the request.--><requestHandler name="standard" class="solr.StandardRequestHandler"/>+ <requestHandler name="dismaxOldStyleDefaults"+ class="solr.DisMaxRequestHandler" >+ <!-- for historic reasons, DisMaxRequestHandler will use all of+ it's init params as "defaults" if there is no "defaults" list+ specified+ -->+ <float name="tie">0.01</float>+ <str name="qf">+ text^0.5 features_t^1.0 subject^1.4 title_stemmed^2.0+ </str>+ <str name="pf">+ text^0.2 features_t^1.1 subject^1.4 title_stemmed^2.0 title^1.5+ </str>+ <str name="bf">+ ord(weight)^0.5 recip(rord(iind),1,1000,1000)^0.3+ </str>+ <str name="mm">+ 3<-1 5<-2 6<90%+ </str>+ <int name="ps">100</int>+ </requestHandler><requestHandler name="dismax" class="solr.DisMaxRequestHandler" >+ <lst name="defaults"><float name="tie">0.01</float><str name="qf">text^0.5 features_t^1.0 subject^1.4 title_stemmed^2.0@@ -183,6 +205,7 @@3<-1 5<-2 6<90%</str><int name="ps">100</int>+ </lst></requestHandler><requestHandler name="old" class="solr.tst.OldRequestHandler" ><int name="myparam">1000</int>