org.elasticsearch.search.sort.SortMode Java Examples

The following examples show how to use org.elasticsearch.search.sort.SortMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryOrderByParser.java    From elasticsearch-sql with MIT License 7 votes vote down vote up
@Override
public void parse(ElasticDslContext dslContext) {
    if(dslContext.getSqlContext().selectOperation()!=null&&dslContext.getSqlContext().selectOperation().groupByClause()==null){
        if(dslContext.getSqlContext().selectOperation().orderClause()!=null){
            ElasticsearchParser.OrderClauseContext orderClauseContext=dslContext.getSqlContext().selectOperation().orderClause();
            for(ElasticsearchParser.OrderContext orderContext:orderClauseContext.order()){
                ElasticsearchParser.NameClauseContext nameContext = orderContext.nameClause();
                if(nameContext instanceof ElasticsearchParser.FieldNameContext){
                    ElasticsearchParser.FieldNameContext fieldNameContext=(ElasticsearchParser.FieldNameContext)nameContext;
                    String field = fieldNameContext.field.getText();
                    if(fieldNameContext.highlighter!=null){
                        dslContext.getParseResult().getHighlighter().add(field);
                    }
                    SortOrder sortOrder;
                    if(orderContext.ASC()!=null) {
                        sortOrder=SortOrder.ASC;
                    }else{
                        sortOrder=SortOrder.DESC;
                    }
                    SortBuilder sortBuilder = SortBuilders.fieldSort(field).sortMode(SortMode.AVG).order(sortOrder);
                    dslContext.getParseResult().getOrderBy().add(sortBuilder);
                }
            }
        }
    }
}
 
Example #2
Source File: SortConverter.java    From james-project with Apache License 2.0 4 votes vote down vote up
public static FieldSortBuilder convertSort(SearchQuery.Sort sort) {
    return getSortClause(sort.getSortClause())
        .order(getOrder(sort))
        .sortMode(SortMode.MIN);
}
 
Example #3
Source File: SortContentBuilder.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
private SortBuilder createSort(SortOrder sortOrder) {
  String field = sortOrder.getField();
  org.elasticsearch.search.sort.SortOrder order = toSortOrder(sortOrder.getDirection());
  return SortBuilders.fieldSort(field).order(order).sortMode(SortMode.MIN);
}