From 74f787bede2f6ba19b8c7e6ccfb856bfc8243083 Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Wed, 6 Sep 2006 19:29:08 +0000 Subject: [PATCH] more progress on SOLR-43 git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@440841 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 4 ++ example/solr/conf/solrconfig.xml | 5 ++ .../solr/request/DisMaxRequestHandler.java | 55 ++++++++++++------- .../org/apache/solr/request/SolrParams.java | 6 ++ .../org/apache/solr/util/DisMaxParams.java | 42 +++++++++++--- .../org/apache/solr/util/SolrPluginUtils.java | 4 ++ .../apache/solr/DisMaxRequestHandlerTest.java | 7 ++- src/test/test-files/solr/conf/solrconfig.xml | 25 ++++++++- 8 files changed, 118 insertions(+), 30 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index f28aa04895b..87e21d6236d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -55,6 +55,10 @@ Changes in runtime behavior 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 '...' 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 diff --git a/example/solr/conf/solrconfig.xml b/example/solr/conf/solrconfig.xml index fe2235d4df6..f63576fc965 100755 --- a/example/solr/conf/solrconfig.xml +++ b/example/solr/conf/solrconfig.xml @@ -193,6 +193,7 @@ its init() method. --> + 0.01 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% 100 + + inStock:true diff --git a/src/java/org/apache/solr/request/DisMaxRequestHandler.java b/src/java/org/apache/solr/request/DisMaxRequestHandler.java index 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; *
  • sort - (Order By) list of fields and direction to sort on. *
  • * + * + *
    + * :TODO: make bf,fq,pf,qf multival params now that SolrParams supports them
    + * 
    */ public class DisMaxRequestHandler implements 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 " 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 queryFields = - U.parseFieldBoosts(U.getParam(req, params.QF, params.qf)); - Map phraseFields = - U.parseFieldBoosts(U.getParam(req, params.PF, params.pf)); + Map queryFields = U.parseFieldBoosts(params.get(DMP.QF)); + Map 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 funcs = U.parseFuncs(schema, boostFunc); for (Query f : funcs) { @@ -296,7 +313,7 @@ public class DisMaxRequestHandler List restrictions = new ArrayList(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.java index 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.java index 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. *

    - * + * @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.java index 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.java index 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.xml index 46f08b87a5f..62498ca595a 100644 --- a/src/test/test-files/solr/conf/solrconfig.xml +++ b/src/test/test-files/solr/conf/solrconfig.xml @@ -168,7 +168,12 @@ is not specified in the request. --> - + + 0.01 text^0.5 features_t^1.0 subject^1.4 title_stemmed^2.0 @@ -184,6 +189,24 @@ 100 + + + 0.01 + + text^0.5 features_t^1.0 subject^1.4 title_stemmed^2.0 + + + text^0.2 features_t^1.1 subject^1.4 title_stemmed^2.0 title^1.5 + + + ord(weight)^0.5 recip(rord(iind),1,1000,1000)^0.3 + + + 3<-1 5<-2 6<90% + + 100 + + 1000 1.4142135