本文整理汇总了Java中org.elasticsearch.search.sort.FieldSortBuilder.order方法的典型用法代码示例。如果您正苦于以下问题:Java FieldSortBuilder.order方法的具体用法?Java FieldSortBuilder.order怎么用?Java FieldSortBuilder.order使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.search.sort.FieldSortBuilder
的用法示例。
在下文中一共展示了FieldSortBuilder.order方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fieldSort
import org.elasticsearch.search.sort.FieldSortBuilder; //导入方法依赖的package包/类
@Override
public QueryBuilderHelper fieldSort(String fieldName, boolean desc) {
if (fieldName == null) {
return this;
}
fieldSort = true;
FieldSortBuilder sortBuilder = SortBuilders.fieldSort(fieldName);
if (desc) {
sortBuilder.order(SortOrder.DESC);
} else {
sortBuilder.order(SortOrder.ASC);
}
// TODO: change to use sortBuilder.unmappedType
sortBuilder.ignoreUnmapped(true);
searchRequestBuilder.addSort(sortBuilder);
return this;
}
示例2: sortToUri
import org.elasticsearch.search.sort.FieldSortBuilder; //导入方法依赖的package包/类
private static String sortToUri(SortBuilder<?> sort) {
if (sort instanceof FieldSortBuilder) {
FieldSortBuilder f = (FieldSortBuilder) sort;
return f.getFieldName() + ":" + f.order();
}
throw new IllegalArgumentException("Unsupported sort [" + sort + "]");
}
示例3: convertFieldSort
import org.elasticsearch.search.sort.FieldSortBuilder; //导入方法依赖的package包/类
public static SortBuilder convertFieldSort(FieldSort fieldSort) {
final FieldSortBuilder fs = SortBuilders.fieldSort(fieldSort.getField());
// Sort Order
switch (fieldSort.getOrder()) {
case ASCENDING:
fs.order(SortOrder.ASC);
break;
case DESCENDING:
fs.order(SortOrder.DESC);
break;
}
// Sort Mode
if (fieldSort.isSetMode()) {
switch (fieldSort.getMode()) {
case SUM:
fs.sortMode("sum");
break;
case AVG:
fs.sortMode("avg");
break;
case MAX:
fs.sortMode("max");
break;
case MIN:
fs.sortMode("min");
break;
default:
throw new IllegalArgumentException("Field sort has unknown mode " + fieldSort.getMode());
}
}
// Ignore Unmapped?
if (fieldSort.isSetIgnoreUnmapped()) {
fs.ignoreUnmapped(fieldSort.ignoreUnmapped);
}
// How to handle missing values
if (fieldSort.isSetMissing()) {
final MissingSort missing = fieldSort.getMissing();
if (missing.isSet(MissingSort._Fields.BASIC)) {
if (missing.getBasic() == MissingOrder.FIRST) {
fs.missing("_first");
} else {
fs.missing("_last");
}
} else {
fs.missing(missing.getCustom());
}
}
return fs;
}