List of usage examples for org.apache.solr.search SortSpecParsing parseSortSpec
public static SortSpec parseSortSpec(String sortSpec, IndexSchema schema)
The form of the (function free) sort specification string currently parsed is:
SortSpec ::= SingleSort [, SingleSort] SingleSort ::= <fieldname> SortDirection SortDirection ::= top | desc | bottom | ascExamples:
score desc #normal sort by score (will return null) weight bottom #sort by weight ascending weight desc #sort by weight descending height desc,weight desc #sort by height descending, and use weight descending to break any ties height desc,weight asc #sort by height descending, using weight ascending as a tiebreaker
From source file:org.alfresco.solr.query.AbstractQParser.java
License:Open Source License
@Override public SortSpec getSortSpec(boolean useGlobalParams) throws SyntaxError { getQuery(); // ensure query is parsed first String sortStr = null;//from www .j ava2 s. c om String startS = null; String rowsS = null; if (localParams != null) { sortStr = localParams.get(CommonParams.SORT); startS = localParams.get(CommonParams.START); rowsS = localParams.get(CommonParams.ROWS); // if any of these parameters are present, don't go back to the global params if (sortStr != null || startS != null || rowsS != null) { useGlobalParams = false; } } if (useGlobalParams) { if (sortStr == null) { sortStr = params.get(CommonParams.SORT); } if (startS == null) { startS = params.get(CommonParams.START); } if (rowsS == null) { rowsS = params.get(CommonParams.ROWS); } } int start = startS != null ? Integer.parseInt(startS) : 0; int rows = rowsS != null ? Integer.parseInt(rowsS) : 10; // Fix sort fields here if (sortStr != null) { StringBuilder builder = new StringBuilder(); StringBuilder propertyBuilder = null; char c; for (int i = 0; i < sortStr.length(); i++) { c = sortStr.charAt(i); if (propertyBuilder == null) { if (!Character.isWhitespace(c) && (c != ',')) { propertyBuilder = new StringBuilder(); propertyBuilder.append(c); } else { builder.append(c); } } else { if (Character.isWhitespace(c) || (c == ',')) { String toAppend = AlfrescoSolrDataModel.getInstance() .mapProperty(propertyBuilder.toString(), FieldUse.SORT, getReq()); builder.append(toAppend); builder.append(c); propertyBuilder = null; } else { propertyBuilder.append(c); } } } if (propertyBuilder != null) { String toAppend = AlfrescoSolrDataModel.getInstance().mapProperty(propertyBuilder.toString(), FieldUse.SORT, getReq()); builder.append(toAppend); } sortStr = builder.toString(); } if (sortStr != null) { sortStr = sortStr.replaceAll("^ID(\\s)", "id$1"); sortStr = sortStr.replaceAll("(\\s)ID(\\s)", "$1id$2"); } SortSpec sort = SortSpecParsing.parseSortSpec(sortStr, req); sort.setOffset(start); sort.setCount(rows); return sort; }