You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ho...@apache.org on 2006/09/06 21:29:09 UTC
svn commit: r440841 - in /incubator/solr/trunk: ./ example/solr/conf/
src/java/org/apache/solr/request/ src/java/org/apache/solr/util/
src/test/org/apache/solr/ src/test/test-files/solr/conf/
Author: hossman
Date: Wed Sep 6 12:29:08 2006
New Revision: 440841
URL: http://svn.apache.org/viewvc?view=rev&rev=440841
Log:
more progress on SOLR-43
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/SolrParams.java
incubator/solr/trunk/src/java/org/apache/solr/util/DisMaxParams.java
incubator/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java
incubator/solr/trunk/src/test/org/apache/solr/DisMaxRequestHandlerTest.java
incubator/solr/trunk/src/test/test-files/solr/conf/solrconfig.xml
Modified: incubator/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/CHANGES.txt?view=diff&rev=440841&r1=440840&r2=440841
==============================================================================
--- incubator/solr/trunk/CHANGES.txt (original)
+++ incubator/solr/trunk/CHANGES.txt Wed Sep 6 12:29:08 2006
@@ -55,6 +55,10 @@
4. Highlighter params changed to be prefixed with "hl."; allow fragmentsize
customization 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)
Optimizations
1. getDocListAndSet can now generate both a DocList and a DocSet from a
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=440841&r1=440840&r2=440841
==============================================================================
--- incubator/solr/trunk/example/solr/conf/solrconfig.xml (original)
+++ incubator/solr/trunk/example/solr/conf/solrconfig.xml Wed Sep 6 12:29:08 2006
@@ -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 with
different 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>
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=440841&r1=440840&r2=440841
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java Wed Sep 6 12:29:08 2006
@@ -35,6 +35,7 @@
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 @@
* <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 DisMaxRequestHandler
implements SolrRequestHandler, SolrInfoMBean {
@@ -127,14 +132,18 @@
// 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 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 @@
/* * * 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 @@
/* * * 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 @@
/* * * 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 @@
List<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 @@
/* * * 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 @@
/* * * 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);
Modified: incubator/solr/trunk/src/java/org/apache/solr/request/SolrParams.java
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/java/org/apache/solr/request/SolrParams.java?view=diff&rev=440841&r1=440840&r2=440841
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/request/SolrParams.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/request/SolrParams.java Wed Sep 6 12:29:08 2006
@@ -72,6 +72,12 @@
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;
}
Modified: incubator/solr/trunk/src/java/org/apache/solr/util/DisMaxParams.java
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/java/org/apache/solr/util/DisMaxParams.java?view=diff&rev=440841&r1=440840&r2=440841
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/util/DisMaxParams.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/util/DisMaxParams.java Wed Sep 6 12:29:08 2006
@@ -65,21 +65,45 @@
/** 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 @@
* 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) {
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=440841&r1=440840&r2=440841
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java Wed Sep 6 12:29:08 2006
@@ -84,6 +84,7 @@
/**
* 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 @@
/**
* 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 @@
/**
* 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 @@
* (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,
Modified: incubator/solr/trunk/src/test/org/apache/solr/DisMaxRequestHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/test/org/apache/solr/DisMaxRequestHandlerTest.java?view=diff&rev=440841&r1=440840&r2=440841
==============================================================================
--- incubator/solr/trunk/src/test/org/apache/solr/DisMaxRequestHandlerTest.java (original)
+++ incubator/solr/trunk/src/test/org/apache/solr/DisMaxRequestHandlerTest.java Wed Sep 6 12:29:08 2006
@@ -96,7 +96,12 @@
}
-
+ public void testOldStyleDefaults() throws Exception {
+
+ lrf = h.getRequestFactory
+ ("dismaxOldStyleDefaults",0,20,"version","2.0");
+ testSomeStuff();
+ }
Modified: incubator/solr/trunk/src/test/test-files/solr/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/test/test-files/solr/conf/solrconfig.xml?view=diff&rev=440841&r1=440840&r2=440841
==============================================================================
--- incubator/solr/trunk/src/test/test-files/solr/conf/solrconfig.xml (original)
+++ incubator/solr/trunk/src/test/test-files/solr/conf/solrconfig.xml Wed Sep 6 12:29:08 2006
@@ -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>