more progress on SOLR-43

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@440841 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2006-09-06 19:29:08 +00:00
parent d34d6aa515
commit 74f787bede
8 changed files with 118 additions and 30 deletions

View File

@ -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 '<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

View File

@ -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&lt;-1 5&lt;-2 6&lt;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>

View File

@ -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 DisMaxRequestHandler
implements SolrRequestHandler, SolrInfoMBean {
@ -128,12 +133,16 @@ public class DisMaxRequestHandler
long numRequests;
long numErrors;
SolrParams defaults;
/** shorten the class referneces for utilities */
private static class U extends SolrPluginUtils {
/* :NOOP */
}
protected final DisMaxParams params = new DisMaxParams();
/** shorten the class referneces for utilities */
private static class DMP extends DisMaxParams {
/* :NOOP */
}
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 DisMaxRequestHandler
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 @@ 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);

View File

@ -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;
}

View File

@ -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) {

View File

@ -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,

View File

@ -96,7 +96,12 @@ public class DisMaxRequestHandlerTest extends AbstractSolrTestCase {
}
public void testOldStyleDefaults() throws Exception {
lrf = h.getRequestFactory
("dismaxOldStyleDefaults",0,20,"version","2.0");
testSomeStuff();
}

View File

@ -168,7 +168,12 @@
is not specified in the request.
-->
<requestHandler name="standard" class="solr.StandardRequestHandler"/>
<requestHandler name="dismax" class="solr.DisMaxRequestHandler" >
<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
@ -184,6 +189,24 @@
</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
</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&lt;-1 5&lt;-2 6&lt;90%
</str>
<int name="ps">100</int>
</lst>
</requestHandler>
<requestHandler name="old" class="solr.tst.OldRequestHandler" >
<int name="myparam">1000</int>
<float name="ratio">1.4142135</float>