/** * Given a string containing fieldNames and boost info, * converts it to a Map from field name to boost info. * * <p> * Doesn't care if boost info is negative, you're on your own. * </p> * <p> * Doesn't care if boost info is missing, again: you're on your own. * </p> * * @param in a String like "fieldOne^2.3 fieldTwo fieldThree^-0.4" * @return Map of fieldOne => 2.3, fieldTwo => null, fieldThree => -0.4 */ public static Map<String,Float> parseFieldBoosts(String in) { return parseFieldBoosts(new String[]{in}); } /**
protected Query getUserQuery(String userQuery, SolrPluginUtils.DisjunctionMaxQueryParser up, SolrParams solrParams) throws ParseException { String minShouldMatch = solrParams.get(DisMaxParams.MM, "100%"); Query dis = up.parse(userQuery); Query query = dis; if (dis instanceof BooleanQuery) { BooleanQuery t = new BooleanQuery(); SolrPluginUtils.flattenBooleanQuery(t, (BooleanQuery) dis); SolrPluginUtils.setMinShouldMatch(t, minShouldMatch); query = t; } return query; }
/** * Calls apache solr to answer the given user request. * * @param q the user query * @param req the solr query request object * @param start start of the query * @param limit the document limit * @return the result of the query * @throws IOException if bad things happen */ @Override public DocList doSimpleQuery(String q, SolrQueryRequest req, int start, int limit) throws IOException { return SolrPluginUtils.doSimpleQuery(q, req, start, limit); }
protected void addMainQuery(BooleanQuery query, SolrParams solrParams) throws ParseException { Map<String, Float> phraseFields = SolrPluginUtils.parseFieldBoosts(solrParams.getParams(DisMaxParams.PF)); float tiebreaker = solrParams.getFloat(DisMaxParams.TIE, 0.0f); /* a parser for dealing with user input, which will convert * things to DisjunctionMaxQueries */ SolrPluginUtils.DisjunctionMaxQueryParser up = getParser(queryFields, DisMaxParams.QS, solrParams, tiebreaker); /* for parsing sloppy phrases using DisjunctionMaxQueries */ SolrPluginUtils.DisjunctionMaxQueryParser pp = getParser(phraseFields, DisMaxParams.PS, solrParams, tiebreaker); /* * * Main User Query * * */ parsedUserQuery = null; String userQuery = getString(); altUserQuery = null; if (userQuery == null || userQuery.trim().length() < 1) { // If no query is specified, we may have an alternate altUserQuery = getAlternateUserQuery(solrParams); query.add(altUserQuery, BooleanClause.Occur.MUST); } else { // There is a valid query string userQuery = SolrPluginUtils.partialEscape(SolrPluginUtils.stripUnbalancedQuotes(userQuery)).toString(); userQuery = SolrPluginUtils.stripIllegalOperators(userQuery).toString(); parsedUserQuery = getUserQuery(userQuery, up, solrParams); query.add(parsedUserQuery, BooleanClause.Occur.MUST); Query phrase = getPhraseQuery(userQuery, pp); if (null != phrase) { query.add(phrase, BooleanClause.Occur.SHOULD); } } }
@Override public Query applyMinimumShouldMatch(final BooleanQuery query) { final List<BooleanClause> clauses = query.clauses(); if (clauses.size() < 2) { return query; } for (final BooleanClause clause : clauses) { if ((clause.getQuery() instanceof BooleanQuery) && (clause.getOccur() != BooleanClause.Occur.MUST)) { return query; // seems to be a complex query with sub queries - do not // apply mm } } return SolrPluginUtils.setMinShouldMatch(query, minShouldMatch); }
throws IOException { String debug = getParam(req, org.apache.solr.common.params.CommonParams.DEBUG_QUERY, params.debugQuery); dbg.add("parsedquery_toString", query.toString()); dbg.add("explain", getExplainList (query, results, req.getSearcher(), req.getSchema())); String otherQueryS = req.getParam("explainOther"); if (otherQueryS != null && otherQueryS.length() > 0) { DocList otherResults = doSimpleQuery (otherQueryS,req.getSearcher(), req.getSchema(),0,10); dbg.add("otherQuery",otherQueryS); dbg.add("explainOther", getExplainList (query, otherResults, req.getSearcher(),
List<Query> filters = SolrPluginUtils.parseFilterQueries(req); int flags = 0; if (fl != null) { flags |= SolrPluginUtils.setReturnFields(fl, rsp); NamedList<Object> dbg = SolrPluginUtils.doStandardDebug(req, q, mlt.mltquery, mltDocs.docList ); if (null != dbg) { if (null != filters) {
/** * Set defaults on a SolrQueryRequest. * * RequestHandlers can use this method to ensure their defaults are * visible to other components such as the response writer */ public static void setDefaults(SolrQueryRequest req, SolrParams defaults) { setDefaults(req, defaults, null, null); }
NamedList<Object> stdDbg = SolrPluginUtils.doStandardDebug(req, q, mltResult.getQuery(), mltDocs.docList, dbgQuery, dbgResults); if (null != dbgInfo) { rsp.add("debug", dbgInfo);
dbg.add("parsedquery_toString", query.toString()); dbg.add("explain", getExplainList (query, results, req.getSearcher(), req.getSchema())); String otherQueryS = req.getParams().get(org.apache.solr.common.params.CommonParams.EXPLAIN_OTHER); if (otherQueryS != null && otherQueryS.length() > 0) { DocList otherResults = doSimpleQuery (otherQueryS,req.getSearcher(), req.getSchema(),0,10); dbg.add("otherQuery",otherQueryS); dbg.add("explainOther", getExplainList (query, otherResults, req.getSearcher(),
/** * Converts the docs into a solr document list. * * @param docs The {@link org.apache.solr.search.DocList} to convert * @param searcher The {@link org.apache.solr.search.SolrIndexSearcher} to use to load the docs from the Lucene index * @param fields The names of the Fields to load * @param ids A map to store the ids of the docs * @return the docs as solr document list. * @throws IOException if bad things happen. */ @Override public SolrDocumentList docListToSolrDocumentList(DocList docs, SolrIndexSearcher searcher, Set<String> fields, Map<SolrDocument, Integer> ids) throws IOException { return SolrPluginUtils.docListToSolrDocumentList(docs, searcher, fields, ids); } }
public Query getOrQuery(){ BooleanQuery.Builder qryBuilder = new BooleanQuery.Builder(); for(MLTTerm mltTerm: this.mltTerms){ qryBuilder.add(toBoostedQuery(mltTerm), BooleanClause.Occur.SHOULD); } SolrPluginUtils.setMinShouldMatch(qryBuilder, mm); return qryBuilder.build(); }
@Override public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) { // Process defaults, appends and invariants if we got a request if(req != null) { SolrPluginUtils.setDefaults(req, defaults, appends, invariants); } return new MultiTextFieldLanguageIdentifierUpdateProcessor(req, rsp, next); }
NamedList<Object> stdDbg = SolrPluginUtils.doStandardDebug(req, q, mltResult.getQuery(), mltDocs.docList, dbgQuery, dbgResults); if (null != dbgInfo) { rsp.add("debug", dbgInfo);
if (results instanceof DocList) { try { docs = SolrPluginUtils.docListToSolrDocumentList ((DocList) results, (SolrIndexSearcher) eval.getSearcher().getWrappedSearcher(), fieldNames, null); } catch (IOException e) {
/** * Given a string containing functions with optional boosts, returns * an array of Queries representing those functions with the specified * boosts. * <p> * NOTE: intra-function whitespace is not allowed. * </p> * @see #parseFieldBoosts * @deprecated */ public static List<Query> parseFuncs(IndexSchema s, String in) throws ParseException { Map<String,Float> ff = parseFieldBoosts(in); List<Query> funcs = new ArrayList<Query>(ff.keySet().size()); for (String f : ff.keySet()) { Query fq = QueryParsing.parseFunction(f, s); Float b = ff.get(f); if (null != b) { fq.setBoost(b); } funcs.add(fq); } return funcs; }
public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) { numRequests++; try { SolrPluginUtils.setDefaults(req,defaults,appends,invariants); rsp.setHttpCaching(httpCaching); handleRequestBody( req, rsp ); // count timeouts NamedList header = rsp.getResponseHeader(); if(header != null) { Object partialResults = header.get("partialResults"); boolean timedOut = partialResults == null ? false : (Boolean)partialResults; if( timedOut ) { numTimeouts++; rsp.setHttpCaching(false); } } } catch (Exception e) { SolrException.log(SolrCore.log,e); if (e instanceof ParseException) { e = new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); } rsp.setException(e); numErrors++; } totalTime += rsp.getEndTime() - req.getStartTime(); }
NamedList stdinfo = SolrPluginUtils.doStandardDebug( rb.req, rb.getQueryString(), rb.getQuery(), rb.getResults().docList);
protected void addBoostFunctions(BooleanQuery query, SolrParams solrParams) throws ParseException { String[] boostFuncs = solrParams.getParams(DisMaxParams.BF); if (null != boostFuncs && 0 != boostFuncs.length) { for (String boostFunc : boostFuncs) { if (null == boostFunc || "".equals(boostFunc)) continue; Map<String, Float> ff = SolrPluginUtils.parseFieldBoosts(boostFunc); for (String f : ff.keySet()) { Query fq = subQuery(f, FunctionQParserPlugin.NAME).parse(); Float b = ff.get(f); if (null != b) { fq.setBoost(b); } query.add(fq, BooleanClause.Occur.SHOULD); } } } }
final Map<String, Float> ff = SolrPluginUtils.parseFieldBoosts(bf); for (final Map.Entry<String, Float> bfAndBoost : ff.entrySet()) {