U.setDefaults(req,defaults,appends,invariants);
SolrParams params = req.getParams();
int flags = 0;
SolrIndexSearcher s = req.getSearcher();
IndexSchema schema = req.getSchema();
Map<String,Float> queryFields = U.parseFieldBoosts(params.get(DMP.QF));
Map<String,Float> phraseFields = U.parseFieldBoosts(params.get(DMP.PF));
float tiebreaker = params.getFloat(DMP.TIE, 0.0f);
int pslop = params.getInt(DMP.PS, 0);
/* a generic parser for parsing regular lucene queries */
QueryParser p = new SolrQueryParser(schema, null);
/* a parser for dealing with user input, which will convert
* things to DisjunctionMaxQueries
*/
U.DisjunctionMaxQueryParser up =
new U.DisjunctionMaxQueryParser(schema, IMPOSSIBLE_FIELD_NAME);
up.addAlias(IMPOSSIBLE_FIELD_NAME,
tiebreaker, queryFields);
/* for parsing slopy phrases using DisjunctionMaxQueries */
U.DisjunctionMaxQueryParser pp =
new U.DisjunctionMaxQueryParser(schema, IMPOSSIBLE_FIELD_NAME);
pp.addAlias(IMPOSSIBLE_FIELD_NAME,
tiebreaker, phraseFields);
pp.setPhraseSlop(pslop);
/* * * Main User Query * * */
String userQuery = U.partialEscape
(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 = params.get(DMP.MM, "100%");
Query dis = up.parse(userQuery);
if (dis instanceof BooleanQuery) {
BooleanQuery t = new BooleanQuery();
U.flattenBooleanQuery(t, (BooleanQuery)dis);
U.setMinShouldMatch(t, minShouldMatch);
query.add(t, Occur.MUST);
} else {
query.add(dis, Occur.MUST);
}
/* * * Add on Phrases for the Query * * */
/* build up phrase boosting queries */
/* if the userQuery already has some quotes, stip them out.
* we've already done the phrases they asked for in the main
* part of the query, this is to boost docs that may not have
* matched those phrases but do match looser phrases.
*/
String userPhraseQuery = userQuery.replace("\"","");
Query phrase = pp.parse("\"" + userPhraseQuery + "\"");
if (null != phrase) {
query.add(phrase, Occur.SHOULD);
}
/* * * Boosting Query * * */
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
* extract the subqueries out and use them directly
*/
if (1.0f == tmp.getBoost() && tmp instanceof BooleanQuery) {
for (BooleanClause c : ((BooleanQuery)tmp).getClauses()) {
query.add(c);
}
} else {
query.add(tmp, BooleanClause.Occur.SHOULD);
}
}
/* * * Boosting Functions * * */
String boostFunc = params.get(DMP.BF);
if (null != boostFunc && !boostFunc.equals("")) {
List<Query> funcs = U.parseFuncs(schema, boostFunc);
for (Query f : funcs) {
query.add(f, Occur.SHOULD);
}
}
/* * * Restrict Results * * */
List<Query> restrictions = U.parseFilterQueries(req);
/* * * Generate Main Results * * */
flags |= U.setReturnFields(req,rsp);
DocListAndSet results = new DocListAndSet();
NamedList facetInfo = null;
if (params.getBool(FACET,false)) {
results = s.getDocListAndSet(query, restrictions,
SolrPluginUtils.getSort(req),
req.getStart(), req.getLimit(),
flags);
facetInfo = getFacetInfo(req, rsp, results.docSet);
} else {
results.docList = s.getDocList(query, restrictions,
SolrPluginUtils.getSort(req),
req.getStart(), req.getLimit(),
flags);
}
rsp.add("response",results.docList);