当前位置: 首页>>代码示例>>Java>>正文


Java SortBuilder.order方法代码示例

本文整理汇总了Java中org.elasticsearch.search.sort.SortBuilder.order方法的典型用法代码示例。如果您正苦于以下问题:Java SortBuilder.order方法的具体用法?Java SortBuilder.order怎么用?Java SortBuilder.order使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.search.sort.SortBuilder的用法示例。


在下文中一共展示了SortBuilder.order方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildSort

import org.elasticsearch.search.sort.SortBuilder; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes" })
private SortBuilder[] buildSort(UAVHttpMessage data) {

    SortBuilder[] sorts = null;

    String sort = data.getRequest("sort");

    if (sort != null) {
        String[] sortFieldStrs = sort.split(",");
        List<SortBuilder> ls = new ArrayList<SortBuilder>();
        for (String sortFieldStr : sortFieldStrs) {
            String[] sortExp = sortFieldStr.split("=");
            SortBuilder stimeSort = new FieldSortBuilder(sortExp[0]);
            stimeSort.order(SortOrder.fromString(sortExp[1]));
            ls.add(stimeSort);
        }
        sorts = new SortBuilder[ls.size()];
        sorts = ls.toArray(sorts);
    }
    else {
        return null;
    }
    return sorts;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:25,代码来源:SlowOperQueryHandler.java

示例2: withScriptSort

import org.elasticsearch.search.sort.SortBuilder; //导入方法依赖的package包/类
public SimpleSearchQueryBuilder withScriptSort(String script, SortOrder order){
	if(StringUtils.isBlank(script))
		return this;
	Script sortScript = new Script(script);
	SortBuilder sortBuilder = SortBuilders.scriptSort(sortScript, "number");
	sortBuilder.order(order);
	this.searchQueryBuilder.withSort(sortBuilder);
	return this;
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:10,代码来源:SimpleSearchQueryBuilder.java

示例3: addSort

import org.elasticsearch.search.sort.SortBuilder; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T extends SearchCriteria> T addSort(String filed, boolean asc) {
	SortBuilder s = new FieldSortBuilder(filed);
	if (asc) {
		s.order(SortOrder.ASC);
	} else {
		s.order(SortOrder.DESC);
	}
	return (T) this;
}
 
开发者ID:yamingd,项目名称:argo,代码行数:12,代码来源:SearchCriteriaImpl.java

示例4: create

import org.elasticsearch.search.sort.SortBuilder; //导入方法依赖的package包/类
private TestContext create(SearchType... searchTypes) throws Exception {
    assertAcked(prepareCreate("index").addMapping("type", jsonBuilder().startObject().startObject("type").startObject("properties")
            .startObject("field1")
                .field("type", "long")
            .endObject()
            .startObject("field2")
                .field("type", "keyword")
            .endObject()
            .startObject("nested")
                .field("type", "nested")
                .startObject("properties")
                    .startObject("field3")
                        .field("type", "long")
                    .endObject()
                    .startObject("field4")
                        .field("type", "keyword")
                    .endObject()
                .endObject()
            .endObject()
            .endObject().endObject().endObject()));

    int numDocs = 2 + randomInt(512);
    int scrollRequestSize = randomIntBetween(1, rarely() ? numDocs : numDocs / 2);
    boolean unevenRouting = randomBoolean();

    int numMissingDocs = scaledRandomIntBetween(0, numDocs / 100);
    IntHashSet missingDocs = new IntHashSet(numMissingDocs);
    for (int i = 0; i < numMissingDocs; i++) {
        while (!missingDocs.add(randomInt(numDocs))) {}
    }

    for (int i = 1; i <= numDocs; i++) {
        IndexRequestBuilder indexRequestBuilder = client()
                .prepareIndex("index", "type", String.valueOf(i));
        if (missingDocs.contains(i)) {
            indexRequestBuilder.setSource("x", "y");
        } else {
            indexRequestBuilder.setSource(jsonBuilder().startObject()
                    .field("field1", i)
                    .field("field2", String.valueOf(i))
                    .startObject("nested")
                        .field("field3", i)
                        .field("field4", String.valueOf(i))
                    .endObject()
                    .endObject());
        }

        if (unevenRouting && randomInt(3) <= 2) {
            indexRequestBuilder.setRouting("a");
        }
        indexRandom(false, indexRequestBuilder);
    }
    refresh();

    final SortBuilder sort;
    if (randomBoolean()) {
        if (randomBoolean()) {
            sort = SortBuilders.fieldSort("field1").missing(1);
        } else {
            sort = SortBuilders.fieldSort("field2")
                    .missing("1");
        }
    } else {
        if (randomBoolean()) {
            sort = SortBuilders.fieldSort("nested.field3").missing(1);
        } else {
            sort = SortBuilders.fieldSort("nested.field4").missing("1");
        }
    }
    sort.order(randomBoolean() ? SortOrder.ASC : SortOrder.DESC);

    SearchType searchType = RandomPicks.randomFrom(random(), Arrays.asList(searchTypes));

    logger.info("numDocs={}, scrollRequestSize={}, sort={}, searchType={}", numDocs, scrollRequestSize, sort, searchType);
    return new TestContext(numDocs, scrollRequestSize, sort, searchType);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:77,代码来源:DuelScrollIT.java


注:本文中的org.elasticsearch.search.sort.SortBuilder.order方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。