List of usage examples for org.apache.solr.handler.component ResponseBuilder setSortSpec
public void setSortSpec(SortSpec sortSpec)
From source file:lux.solr.XQueryComponent.java
License:Mozilla Public License
/** * Process for a distributed search. This method is called at various stages * during the processing of a request:/* w w w . ja va2s. c o m*/ * * During ResponseBuilder.STAGE_PARSE_QUERY we parse, optimize, compile and * execute the XQuery query. When a lux:search call is encountered, it will * create a SearchResultIterator, which creates a Lucene Query and calls * back into the SearchHandler; then subsequent phases are handled by the * normal QueryComponent. * * @return the next stage for this component */ @Override public int distributedProcess(ResponseBuilder rb) throws IOException { if (rb.grouping()) { throw new SolrException(ErrorCode.BAD_REQUEST, "Solr grouping not supported for XQuery"); } if (rb.stage == ResponseBuilder.STAGE_PARSE_QUERY) { if (rb.req instanceof CloudQueryRequest) { CloudQueryRequest cloudReq = (CloudQueryRequest) rb.req; // the sort spec has already been generated rb.setSortSpec(cloudReq.getSortSpec()); return ResponseBuilder.STAGE_EXECUTE_QUERY; } else { process(rb); return ResponseBuilder.STAGE_DONE; } } else { return super.distributedProcess(rb); } }
From source file:opennlp.tools.similarity.apps.solr.IterativeQueryComponent.java
License:Apache License
private ResponseBuilder substituteField(ResponseBuilder rb, String newFieldName) { SolrParams params = rb.req.getParams(); String query = params.get("q"); String currField = StringUtils.substringBetween(" " + query, " ", ":"); if (currField != null && newFieldName != null) query = query.replace(currField, newFieldName); NamedList values = params.toNamedList(); values.remove("q"); values.add("q", query); params = SolrParams.toSolrParams(values); rb.req.setParams(params);/*from w ww .ja v a 2 s .c om*/ rb.setQueryString(query); String defType = params.get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE); // get it from the response builder to give a different component a chance // to set it. String queryString = rb.getQueryString(); if (queryString == null) { // this is the normal way it's set. queryString = params.get(CommonParams.Q); rb.setQueryString(queryString); } QParser parser = null; try { parser = QParser.getParser(rb.getQueryString(), defType, rb.req); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Query q = null; try { q = parser.getQuery(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if (q == null) { // normalize a null query to a query that matches nothing q = new BooleanQuery(); } rb.setQuery(q); try { rb.setSortSpec(parser.getSort(true)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } rb.setQparser(parser); /* try { rb.setScoreDoc(parser.getPaging()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } */ String[] fqs = rb.req.getParams().getParams(CommonParams.FQ); if (fqs != null && fqs.length != 0) { List<Query> filters = rb.getFilters(); if (filters == null) { filters = new ArrayList<Query>(fqs.length); } for (String fq : fqs) { if (fq != null && fq.trim().length() != 0) { QParser fqp = null; try { fqp = QParser.getParser(fq, null, rb.req); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { filters.add(fqp.getQuery()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // only set the filters if they are not empty otherwise // fq=&someotherParam= will trigger all docs filter for every request // if filter cache is disabled if (!filters.isEmpty()) { rb.setFilters(filters); } } return rb; }