/** * Executes a basic query in lucene syntax */ public static DocList doSimpleQuery(String sreq, SolrIndexSearcher searcher, IndexSchema schema, int start, int limit) throws IOException { List<String> commands = StrUtils.splitSmart(sreq,';'); String qs = commands.size() >= 1 ? commands.get(0) : ""; Query query = QueryParsing.parseQuery(qs, schema); // If the first non-query, non-filter command is a simple sort on an indexed field, then // we can use the Lucene sort ability. Sort sort = null; if (commands.size() >= 2) { sort = QueryParsing.parseSort(commands.get(1), schema); } DocList results = searcher.getDocList(query,(DocSet)null, sort, start, limit); return results; }
@Override public SortSpec getSort(boolean useGlobal) throws ParseException { SortSpec sort = super.getSort(useGlobal); if (sortStr != null && sortStr.length()>0 && sort.getSort()==null) { Sort oldSort = QueryParsing.parseSort(sortStr, getReq().getSchema()); if( oldSort != null ) { sort.sort = oldSort; } } return sort; }
/** * Determines the correct Sort based on the request parameter "sort" * * @return null if no sort is specified. */ public static Sort getSort(SolrQueryRequest req) { String sort = req.getParams().get(org.apache.solr.common.params.CommonParams.SORT); if (null == sort || sort.equals("")) { return null; } SolrException sortE = null; Sort ss = null; try { ss = QueryParsing.parseSort(sort, req.getSchema()); } catch (SolrException e) { sortE = e; } if ((null == ss) || (null != sortE)) { /* we definitely had some sort of sort string from the user, * but no SortSpec came out of it */ SolrCore.log.warn("Invalid sort \""+sort+"\" was specified, ignoring", sortE); return null; } return ss; }
sort = QueryParsing.parseSort(commands.get(1), req.getSchema());
sort = QueryParsing.parseSort(sortStr, req.getSchema());
sort = QueryParsing.parseSort(commands.get(1), req.getSchema());