本文整理汇总了Java中org.elasticsearch.search.sort.SortOrder.DESC属性的典型用法代码示例。如果您正苦于以下问题:Java SortOrder.DESC属性的具体用法?Java SortOrder.DESC怎么用?Java SortOrder.DESC使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.elasticsearch.search.sort.SortOrder
的用法示例。
在下文中一共展示了SortOrder.DESC属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applySort
protected void applySort(SearchRequestBuilder q) {
for (SortContainer sortContainer : getParameters().getSortContainers()) {
SortOrder esOrder = sortContainer.direction == SortDirection.ASCENDING ? SortOrder.ASC : SortOrder.DESC;
if (Element.ID_PROPERTY_NAME.equals(sortContainer.propertyName)) {
q.addSort("_uid", esOrder);
} else if (Edge.LABEL_PROPERTY_NAME.equals(sortContainer.propertyName)) {
q.addSort(Elasticsearch5SearchIndex.EDGE_LABEL_FIELD_NAME, esOrder);
} else {
PropertyDefinition propertyDefinition = getGraph().getPropertyDefinition(sortContainer.propertyName);
if (propertyDefinition == null) {
continue;
}
if (!getSearchIndex().isPropertyInIndex(getGraph(), sortContainer.propertyName)) {
continue;
}
if (!propertyDefinition.isSortable()) {
throw new MemgraphException("Cannot sort on non-sortable fields");
}
String[] propertyNames = getPropertyNames(propertyDefinition.getPropertyName());
if (propertyNames.length > 1) {
String scriptSrc = "def fieldValues = []; for (def fieldName : params.fieldNames) { fieldValues.addAll(doc[fieldName].values); } " +
"if (params.esOrder == 'asc') { Collections.sort(fieldValues); } else { Collections.sort(fieldValues, Collections.reverseOrder()); }" +
"if (params.dataType == 'String') { return fieldValues; } else { return fieldValues.length > 0 ? fieldValues[0] : (params.esOrder == 'asc' ? Integer.MAX_VALUE : Integer.MIN_VALUE); }";
List<String> fieldNames = Arrays.stream(propertyNames).map(propertyName ->
propertyName + (propertyDefinition.getDataType() == String.class ? Elasticsearch5SearchIndex.EXACT_MATCH_PROPERTY_NAME_SUFFIX : "")
).collect(Collectors.toList());
HashMap<String, Object> scriptParams = new HashMap<>();
scriptParams.put("fieldNames", fieldNames);
scriptParams.put("esOrder", esOrder == SortOrder.DESC ? "desc" : "asc");
scriptParams.put("dataType", propertyDefinition.getDataType().getSimpleName());
Script script = new Script(ScriptType.INLINE, "painless", scriptSrc, scriptParams);
ScriptSortBuilder.ScriptSortType sortType = propertyDefinition.getDataType() == String.class ? ScriptSortBuilder.ScriptSortType.STRING : ScriptSortBuilder.ScriptSortType.NUMBER;
q.addSort(SortBuilders.scriptSort(script, sortType)
.order(esOrder)
.sortMode(esOrder == SortOrder.DESC ? SortMode.MAX : SortMode.MIN));
} else {
String sortField = propertyNames[0];
if (propertyDefinition.getDataType() == String.class) {
sortField += Elasticsearch5SearchIndex.EXACT_MATCH_PROPERTY_NAME_SUFFIX;
}
q.addSort(sortField, esOrder);
}
}
}
}
示例2: searchQueryRaw
/**
* Executes an ElasticSearch query. This is the core method of the class.
* @param appid name of the {@link com.erudika.para.core.App}
* @param type type of object
* @param query the search query builder
* @param pager a {@link com.erudika.para.utils.Pager}
* @return a list of search results
*/
protected SearchHits searchQueryRaw(String appid, String type, QueryBuilder query, Pager... pager) {
if (StringUtils.isBlank(appid)) {
return null;
}
Pager page = ElasticSearchUtils.getPager(pager);
SortOrder order = page.isDesc() ? SortOrder.DESC : SortOrder.ASC;
int max = page.getLimit();
int pageNum = (int) page.getPage();
int start = (pageNum < 1 || pageNum > Config.MAX_PAGES) ? 0 : (pageNum - 1) * max;
if (query == null) {
query = matchAllQuery();
}
if (!StringUtils.isBlank(type)) {
query = boolQuery().must(query).must(termQuery(Config._TYPE, type));
}
SearchHits hits = null;
try {
SearchRequestBuilder srb = client().prepareSearch(getIndexName(appid)).
setSearchType(SearchType.DFS_QUERY_THEN_FETCH).
setQuery(query).
setSize(max);
if (pageNum <= 1 && !StringUtils.isBlank(page.getLastKey())) {
srb.searchAfter(new Object[]{NumberUtils.toLong(page.getLastKey())});
srb.setFrom(0);
srb.addSort(SortBuilders.fieldSort("_docid").order(order));
} else {
srb.setFrom(start);
for (SortBuilder<?> sortField : ElasticSearchUtils.getSortFieldsFromPager(page)) {
srb.addSort(sortField);
}
}
logger.debug("Elasticsearch query: {}", srb.toString());
hits = srb.execute().actionGet().getHits();
page.setCount(hits.getTotalHits());
if (hits.getHits().length > 0) {
Object id = hits.getAt(hits.getHits().length - 1).getSourceAsMap().get("_docid");
if (id != null) {
page.setLastKey(id.toString());
}
}
} catch (Exception e) {
Throwable cause = e.getCause();
String msg = cause != null ? cause.getMessage() : e.getMessage();
logger.warn("No search results for type '{}' in app '{}': {}.", type, appid, msg);
}
return hits;
}
示例3: getSortOrder
/**
* Method to return the sorting order on basis of string param .
*/
private static SortOrder getSortOrder(String value) {
return value.equalsIgnoreCase(ASC_ORDER) ? SortOrder.ASC : SortOrder.DESC;
}