• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java GeoDistanceSortBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.elasticsearch.search.sort.GeoDistanceSortBuilder的典型用法代码示例。如果您正苦于以下问题:Java GeoDistanceSortBuilder类的具体用法?Java GeoDistanceSortBuilder怎么用?Java GeoDistanceSortBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



GeoDistanceSortBuilder类属于org.elasticsearch.search.sort包,在下文中一共展示了GeoDistanceSortBuilder类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: applyDefaultSortPredicates

import org.elasticsearch.search.sort.GeoDistanceSortBuilder; //导入依赖的package包/类
/**
 * Apply our default sort predicate logic
 */
private void applyDefaultSortPredicates( final SearchRequestBuilder srb, final GeoSortFields geoFields ) {
    //we have geo fields, sort through them in visit order
    for ( String geoField : geoFields.fields() ) {

        final GeoDistanceSortBuilder geoSort = geoFields.applyOrder( geoField, SortOrder.ASC );

        srb.addSort( geoSort );
    }

    //now sort by edge timestamp, then entity id
    //sort by the edge timestamp
    srb.addSort( SortBuilders.fieldSort( IndexingUtils.EDGE_TIMESTAMP_FIELDNAME ).order( SortOrder.DESC ) );

    // removing secondary sort by entity ID -- takes ES resources and provides no benefit
    //sort by the entity id if our times are equal
    //srb.addSort( SortBuilders.fieldSort( IndexingUtils.ENTITY_ID_FIELDNAME ).order( SortOrder.ASC ) );

    return;
}
 
开发者ID:apache,项目名称:usergrid,代码行数:23,代码来源:SearchRequestBuilderStrategy.java


示例2: searchDrivers

import org.elasticsearch.search.sort.GeoDistanceSortBuilder; //导入依赖的package包/类
private List<String> searchDrivers(String backendId, Course course) {

		AppConfigurationSettings settings = SettingsResource.get()//
				.load(AppConfigurationSettings.class);

		int maxDistanceToCustomer = settings.maxDistanceToCustomerFromEligibleDriversInMeters;
		int maxDistanceBetweenDrivers = settings.maxDistanceBetweenEligibleDriversInMeters;
		int obsolescence = settings.driverLastLocationObsolescenceInMinutes;

		BoolQueryBuilder query = QueryBuilders.boolQuery()//
				.must(QueryBuilders.termQuery(STATUS, "working"))//
				.must(QueryBuilders.termsQuery("vehicule.type", //
						compatibleVehiculeTypes(course.requestedVehiculeType)))//
				.must(QueryBuilders.rangeQuery("lastLocation.when")//
						.gt("now-" + obsolescence + "m"));

		GeoDistanceSortBuilder sort = SortBuilders.geoDistanceSort("lastLocation.where")//
				.point(course.from.geopoint.lat, course.from.geopoint.lon)//
				.order(SortOrder.ASC).unit(DistanceUnit.METERS).sortMode("min");

		SearchResponse response = Start.get().getElasticClient()//
				.prepareSearch(backendId, "driver").setQuery(query).setSize(5)//
				.setFetchSource(false).addField(CREDENTIALS_ID)//
				.addSort(sort).get();

		double closestDriverDistance = -1;
		List<String> credentialsIds = new ArrayList<>(5);

		for (SearchHit hit : response.getHits().hits()) {
			double driverDistance = distance(hit);
			if (closestDriverDistance < 0)
				closestDriverDistance = driverDistance;
			if (!isDriverEligible(driverDistance, closestDriverDistance, //
					maxDistanceToCustomer, maxDistanceBetweenDrivers))
				break;
			credentialsIds.add(hit.field(CREDENTIALS_ID).getValue());
		}

		return credentialsIds;
	}
 
开发者ID:spacedog-io,项目名称:spacedog-server,代码行数:41,代码来源:CaremenResource.java


示例3: queryForPosts

import org.elasticsearch.search.sort.GeoDistanceSortBuilder; //导入依赖的package包/类
public List<AbstractPost> queryForPosts(double lon, double lat, double distanceInMeters, int timeInMins){
    List<AbstractPost> results = new ArrayList<>();
    long timeCutoff = ((new Date().getTime() / 1000) - timeInMins * 60);
    long now = (new Date().getTime() / 1000) + 60;  // + 60 is just to make sure to not miss anything

    GeoDistanceFilterBuilder gdFilter = FilterBuilders.geoDistanceFilter("coordinates")
            .point(lon,lat)
            .distance(distanceInMeters, DistanceUnit.METERS)
            .optimizeBbox("memory")
            .geoDistance(GeoDistance.ARC);

    RangeFilterBuilder rFilter = new RangeFilterBuilder("indexDate")
            .from(timeCutoff)
            .to(now);

    AndFilterBuilder andFilter = FilterBuilders.andFilter(rFilter,gdFilter);

    SearchResponse response = CLIENT.prepareSearch(POST_INDEX)
            .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), andFilter))
            .setSize(100)
            .addSort(new GeoDistanceSortBuilder("coordinates").point(lon, lat))
            .execute()
            .actionGet();

    for (SearchHit hit : response.getHits()){
        try{
            String type = (String)hit.getSource().get("myType");
            AbstractPost post = (AbstractPost) new Gson().fromJson(hit.getSourceAsString(), Class.forName(type));
            results.add(post);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    return results;
}
 
开发者ID:txtData,项目名称:socialradar,代码行数:36,代码来源:ElasticsearchConnectionManager.java


示例4: addGeoDistanceSort

import org.elasticsearch.search.sort.GeoDistanceSortBuilder; //导入依赖的package包/类
public ElasticSearchPlaceQuery addGeoDistanceSort(double lon, double lat) {
	GeoDistanceSortBuilder sortBuilder = SortBuilders.geoDistanceSort("prefLocation.coordinates");
	sortBuilder.order(SortOrder.ASC);
	sortBuilder.point(lat, lon);
	requestBuilder.addSort(sortBuilder);
	return this;
}
 
开发者ID:dainst,项目名称:gazetteer,代码行数:8,代码来源:ElasticSearchPlaceQuery.java


示例5: registerSorts

import org.elasticsearch.search.sort.GeoDistanceSortBuilder; //导入依赖的package包/类
private void registerSorts() {
    namedWriteables.add(new NamedWriteableRegistry.Entry(SortBuilder.class, GeoDistanceSortBuilder.NAME, GeoDistanceSortBuilder::new));
    namedWriteables.add(new NamedWriteableRegistry.Entry(SortBuilder.class, ScoreSortBuilder.NAME, ScoreSortBuilder::new));
    namedWriteables.add(new NamedWriteableRegistry.Entry(SortBuilder.class, ScriptSortBuilder.NAME, ScriptSortBuilder::new));
    namedWriteables.add(new NamedWriteableRegistry.Entry(SortBuilder.class, FieldSortBuilder.NAME, FieldSortBuilder::new));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:SearchModule.java


示例6: convertGeoSort

import org.elasticsearch.search.sort.GeoDistanceSortBuilder; //导入依赖的package包/类
public static SortBuilder convertGeoSort(GeoDistanceSort geoDistanceSort) {
    final GeoDistanceSortBuilder gs = SortBuilders.geoDistanceSort(geoDistanceSort.getField());

    // Sort Order
    switch (geoDistanceSort.getOrder()) {
        case ASCENDING:
            gs.order(SortOrder.ASC);
            break;
        case DESCENDING:
            gs.order(SortOrder.DESC);
            break;
    }

    // Unit
    gs.unit(DistanceUnit.valueOf(geoDistanceSort.getUnit().toString()));

    // Value
    final GeoSortValue geoVal = geoDistanceSort.getValue();
    if (geoVal.isSet(GeoSortValue._Fields.GEO_HASH)) {
        gs.geohash(geoVal.getGeoHash());
    } else {
        gs.point(geoVal.getCoordinate().getLatitude(), geoVal.getCoordinate().getLongitude());
    }

    // Sort Mode
    if (geoDistanceSort.isSetMode()) {
        switch (geoDistanceSort.getMode()) {
            case AVG:
                gs.sortMode("avg");
                break;
            case MAX:
                gs.sortMode("max");
                break;
            case MIN:
                gs.sortMode("min");
                break;
            case SUM:
                throw new IllegalArgumentException("Geo distance sort does not support SUM as a mode");
            default:
                throw new IllegalArgumentException(
                        "Geo distance sort has unknown mode " + geoDistanceSort.getMode());
        }
    }

    return gs;
}
 
开发者ID:ezbake,项目名称:ezelastic,代码行数:47,代码来源:ElasticUtils.java


示例7: applySortPredicates

import org.elasticsearch.search.sort.GeoDistanceSortBuilder; //导入依赖的package包/类
/**
 * Invoked when there are sort predicates
 */
private void applySortPredicates( final SearchRequestBuilder srb, final List<SortPredicate> sortPredicates,
                                  final GeoSortFields geoFields, final Map<String, Class> knownFieldsWithType ) {

    Preconditions.checkNotNull(sortPredicates, "sort predicates list cannot be null");

    for ( SortPredicate sp : sortPredicates ) {

        final SortOrder order = sp.getDirection().toEsSort();
        final String propertyName = sp.getPropertyName();

        // if the user specified a geo field in their sort, then honor their sort order and use the field they
        // specified. this is added first so it's known on the response hit when fetching the geo distance later
        // see org.apache.usergrid.persistence.index.impl.IndexingUtils.parseIndexDocId(org.elasticsearch.search.SearchHit, boolean)
        if ( geoFields.contains( propertyName ) ) {
            final GeoDistanceSortBuilder geoSort = geoFields.applyOrder( propertyName, SortOrder.ASC );
            srb.addSort( geoSort );
        }
        // fieldsWithType gives the caller an option to provide any schema related details on properties that
        // might appear in a sort predicate.  loop through these and set a specific sort, rather than adding a sort
        // for all possible types
        else if ( knownFieldsWithType != null && knownFieldsWithType.size() > 0 && knownFieldsWithType.containsKey(propertyName)) {

            String esFieldName = EsQueryVistor.getFieldNameForClass(knownFieldsWithType.get(propertyName));
            // always make sure string sorts use the unanalyzed field
            if ( esFieldName.equals(IndexingUtils.FIELD_STRING_NESTED)){
                esFieldName = IndexingUtils.FIELD_STRING_NESTED_UNANALYZED;
            }

            srb.addSort( createSort( order, esFieldName, propertyName ) );

        }
        //apply regular sort logic which check all possible data types, since this is not a known property name
        else {

            //sort order is arbitrary if the user changes data types.  Double, long, string, boolean are supported
            //default sort types
            srb.addSort( createSort( order, IndexingUtils.FIELD_DOUBLE_NESTED, propertyName ) );
            srb.addSort( createSort( order, IndexingUtils.FIELD_LONG_NESTED, propertyName ) );

            /**
             * We always want to sort by the unanalyzed string field to ensure correct ordering
             */
            srb.addSort( createSort( order, IndexingUtils.FIELD_STRING_NESTED_UNANALYZED, propertyName ) );
            srb.addSort( createSort( order, IndexingUtils.FIELD_BOOLEAN_NESTED, propertyName ) );
        }
    }
}
 
开发者ID:apache,项目名称:usergrid,代码行数:51,代码来源:SearchRequestBuilderStrategy.java


示例8: visit

import org.elasticsearch.search.sort.GeoDistanceSortBuilder; //导入依赖的package包/类
@Override
public void visit( WithinOperand op ) {

    final String name = op.getProperty().getValue().toLowerCase();


    float lat = op.getLatitude().getFloatValue();
    float lon = op.getLongitude().getFloatValue();
    float distance = op.getDistance().getFloatValue();


    final FilterBuilder fb =
            FilterBuilders.geoDistanceFilter( IndexingUtils.FIELD_LOCATION_NESTED ).lat( lat ).lon( lon )
                          .distance( distance, DistanceUnit.METERS );


    filterBuilders.push( fieldNameTerm( name, fb ) );


    //create our geo-sort based off of this point specified

    //this geoSort won't has a sort on it

    final GeoDistanceSortBuilder geoSort =
            SortBuilders.geoDistanceSort( IndexingUtils.FIELD_LOCATION_NESTED ).unit( DistanceUnit.METERS )
                        .geoDistance(GeoDistance.SLOPPY_ARC).point(lat, lon);

    final TermFilterBuilder sortPropertyName = sortPropertyTermFilter(name);

    geoSort.setNestedFilter( sortPropertyName );


    geoSortFields.addField(name, geoSort);
    //no op for query, push


    queryBuilders.push( NoOpQueryBuilder.INSTANCE );
}
 
开发者ID:apache,项目名称:usergrid,代码行数:39,代码来源:EsQueryVistor.java


示例9: applyOrder

import org.elasticsearch.search.sort.GeoDistanceSortBuilder; //导入依赖的package包/类
/**
 * Apply the ordering to our geo sorts. Note this will modify the object stored in this geoSort
 * @param name
 * @param sortOrder
 */
public GeoDistanceSortBuilder applyOrder( final String name, SortOrder sortOrder ){

    final GeoDistanceSortBuilder geoDistanceSortBuilder = geoSorts.get( name );

    geoDistanceSortBuilder.order( sortOrder );

    return geoDistanceSortBuilder;
}
 
开发者ID:apache,项目名称:usergrid,代码行数:14,代码来源:GeoSortFields.java


示例10: addField

import org.elasticsearch.search.sort.GeoDistanceSortBuilder; //导入依赖的package包/类
/**
 * Add a geo sort field to this sorts
 * @param name
 * @param sortBuilder
 */
public void addField(final String name, final GeoDistanceSortBuilder sortBuilder){
    this.geoSorts.put( name, sortBuilder );
}
 
开发者ID:apache,项目名称:usergrid,代码行数:9,代码来源:GeoSortFields.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Sku类代码示例发布时间:2022-05-23
下一篇:
Java PrompterException类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap