use of org.apache.jackrabbit.core.query.lucene.sort.DynamicOperandFieldComparatorSource in project jackrabbit by apache.
the class QueryEngine method createSortFields.
public SortField[] createSortFields(Ordering[] orderings, Session session) throws RepositoryException {
if (orderings == null || orderings.length == 0) {
return new SortField[] { SortField.FIELD_SCORE };
}
// orderings[] -> (property, ordering)
Map<String, Ordering> orderByProperties = new HashMap<String, Ordering>();
for (Ordering o : orderings) {
final String p = o.toString();
if (!orderByProperties.containsKey(p)) {
orderByProperties.put(p, o);
}
}
final DynamicOperandFieldComparatorSource dofcs = new DynamicOperandFieldComparatorSource(session, evaluator, orderByProperties);
List<SortField> sortFields = new ArrayList<SortField>();
// insertion order
for (Ordering o : orderings) {
final String p = o.toString();
// order on jcr:score does not use the natural order as
// implemented in lucene. score ascending in lucene means that
// higher scores are first. JCR specs that lower score values
// are first.
boolean isAsc = QueryObjectModelConstants.JCR_ORDER_ASCENDING.equals(o.getOrder());
if (JcrConstants.JCR_SCORE.equals(p)) {
sortFields.add(new SortField(null, SortField.SCORE, !isAsc));
} else {
// TODO use native sort if available
sortFields.add(new SortField(p, dofcs, !isAsc));
}
}
return sortFields.toArray(new SortField[sortFields.size()]);
}
Aggregations