use of com.b2international.index.query.SortBy.SortByScript in project snow-owl by b2ihealthcare.
the class EsDocumentSearcher method addSort.
private void addSort(DocumentMapping mapping, SearchSourceBuilder reqSource, SortBy sortBy) {
for (final SortBy item : getSortFields(sortBy)) {
if (item instanceof SortByField) {
SortByField sortByField = (SortByField) item;
String field = sortByField.getField();
SortBy.Order order = sortByField.getOrder();
SortOrder sortOrder = order == SortBy.Order.ASC ? SortOrder.ASC : SortOrder.DESC;
switch(field) {
case SortBy.FIELD_SCORE:
// XXX: default order for scores is *descending*
reqSource.sort(SortBuilders.scoreSort().order(sortOrder));
break;
case SortBy.FIELD_DEFAULT:
// Replace special field with default sort field from mapping
reqSource.sort(SortBuilders.fieldSort(mapping.getDefaultSortField()).order(sortOrder));
break;
default:
// Use field name directly otherwise
reqSource.sort(SortBuilders.fieldSort(field).order(sortOrder));
break;
}
} else if (item instanceof SortByScript) {
SortByScript sortByScript = (SortByScript) item;
SortBy.Order order = sortByScript.getOrder();
SortOrder sortOrder = order == SortBy.Order.ASC ? SortOrder.ASC : SortOrder.DESC;
reqSource.sort(SortBuilders.scriptSort(sortByScript.toEsScript(mapping), sortByScript.getSortType()).order(sortOrder));
} else {
throw new UnsupportedOperationException("Unsupported SortBy implementation " + item);
}
}
}
Aggregations