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


Java DistanceUnit类代码示例

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


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

示例1: distance

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
@Override
protected NumericDoubleValues distance(LeafReaderContext context) {
    final MultiGeoPointValues geoPointValues = fieldData.load(context).getGeoPointValues();
    return mode.select(new MultiValueMode.UnsortedNumericDoubleValues() {
        @Override
        public int count() {
            return geoPointValues.count();
        }

        @Override
        public void setDocument(int docId) {
            geoPointValues.setDocument(docId);
        }

        @Override
        public double valueAt(int index) {
            GeoPoint other = geoPointValues.valueAt(index);
            return Math.max(0.0d,
                    distFunction.calculate(origin.lat(), origin.lon(), other.lat(), other.lon(), DistanceUnit.METERS) - offset);
        }
    }, 0.0);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:DecayFunctionBuilder.java

示例2: testArcDistanceVsPlaneInEllipsis

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
/**
 * The old plane calculation in 1.x/2.x incorrectly computed the plane distance in decimal degrees. This test is
 * well intended but bogus. todo: fix w/ new plane distance calculation
 * note: plane distance error varies by latitude so the test will need to correctly estimate expected error
 */
@AwaitsFix(bugUrl = "old plane calculation incorrectly computed everything in degrees. fix this bogus test")
public void testArcDistanceVsPlaneInEllipsis() {
    GeoPoint centre = new GeoPoint(48.8534100, 2.3488000);
    GeoPoint northernPoint = new GeoPoint(48.8801108681, 2.35152032666);
    GeoPoint westernPoint = new GeoPoint(48.85265, 2.308896);

    // With GeoDistance.ARC both the northern and western points are within the 4km range
    assertThat(GeoDistance.ARC.calculate(centre.lat(), centre.lon(), northernPoint.lat(),
            northernPoint.lon(), DistanceUnit.KILOMETERS), lessThan(4D));
    assertThat(GeoDistance.ARC.calculate(centre.lat(), centre.lon(), westernPoint.lat(),
            westernPoint.lon(), DistanceUnit.KILOMETERS), lessThan(4D));

    // With GeoDistance.PLANE, only the northern point is within the 4km range,
    // the western point is outside of the range due to the simple math it employs,
    // meaning results will appear elliptical
    assertThat(GeoDistance.PLANE.calculate(centre.lat(), centre.lon(), northernPoint.lat(),
            northernPoint.lon(), DistanceUnit.KILOMETERS), lessThan(4D));
    assertThat(GeoDistance.PLANE.calculate(centre.lat(), centre.lon(), westernPoint.lat(),
            westernPoint.lon(), DistanceUnit.KILOMETERS), greaterThan(4D));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:GeoDistanceTests.java

示例3: distance

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
@Override
protected NumericDoubleValues distance(LeafReaderContext context) {
    final MultiGeoPointValues geoPointValues = fieldData.load(context).getGeoPointValues();
    return mode.select(new MultiValueMode.UnsortedNumericDoubleValues() {
        @Override
        public int count() {
            return geoPointValues.count();
        }

        @Override
        public void setDocument(int docId) {
            geoPointValues.setDocument(docId);
        }

        @Override
        public double valueAt(int index) {
            GeoPoint other = geoPointValues.valueAt(index);
            return Math.max(0.0d, distFunction.calculate(origin.lat(), origin.lon(), other.lat(), other.lon(), DistanceUnit.METERS) - offset);
        }
    }, 0.0);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:DecayFunctionParser.java

示例4: resolveGridLevel

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
private Integer resolveGridLevel(Optional<Double> distErrOp, Optional<Double> distErrPctOp) {
    SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.Intersects, this.inputShape);
    if (distErrOp.isPresent()) {
        spatialArgs.setDistErr(distErrOp.get() * DistanceUnit.DEFAULT.getDistancePerDegree());
    }    
    spatialArgs.setDistErrPct(distErrPctOp.orElse(DEFAULT_DIST_ERR_PCT));
    double distErr = spatialArgs.resolveDistErr(strategy.getSpatialContext(), DEFAULT_DIST_ERR_PCT);
    if (distErr <= 0) {
      throw new AggregationInitializationException(String.format(Locale.ROOT,
          "%s or %s should be > 0 or instead provide %s=%s for absolute maximum detail", 
              GeoHeatmapAggregationBuilder.DIST_ERR_PCT_FIELD, 
              GeoHeatmapAggregationBuilder.DIST_ERR_FIELD,
              GeoHeatmapAggregationBuilder.GRID_LEVEL_FIELD,
              strategy.getGrid().getMaxLevels()));
    }
    return strategy.getGrid().getLevelForDistance(distErr);
}
 
开发者ID:boundlessgeo,项目名称:elasticsearch-heatmap,代码行数:18,代码来源:GeoHeatmapAggregatorFactory.java

示例5: findPropertiesByLocation

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
@Override
public List<Property> findPropertiesByLocation(final GeoPoint geoPoint, Double distance, final SortOrder sortOrder) {
    GeoDistanceFilterBuilder filter = FilterBuilders.geoDistanceFilter("location").point(geoPoint.getLat(), geoPoint.getLon())
            .distance(distance, DistanceUnit.KILOMETERS);

    SearchQuery searchQuery = new NativeSearchQueryBuilder()
            .withFilter(filter)
            .withSort(
                    SortBuilders.geoDistanceSort("location").point(geoPoint.getLat(), geoPoint.getLon())
                            .order(sortOrder == null ? SortOrder.ASC : sortOrder)).build();

    searchQuery.addIndices("searchahouse");
    searchQuery.addTypes("property");

    List<Property> properties = this.elasticsearchOperations.queryForList(searchQuery, Property.class);

    return properties;
}
 
开发者ID:gustavoorsi,项目名称:searchahouse.com,代码行数:19,代码来源:PropertyServiceImpl.java

示例6: GeoDistanceRangeAggregatorFactory

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
public GeoDistanceRangeAggregatorFactory(String name, ValuesSourceConfig<ValuesSource.GeoPoint> config, GeoPoint origin,
        Range[] ranges, DistanceUnit unit, GeoDistance distanceType, boolean keyed, SearchContext context,
        AggregatorFactory<?> parent, AggregatorFactories.Builder subFactoriesBuilder, Map<String, Object> metaData) throws IOException {
    super(name, config, context, parent, subFactoriesBuilder, metaData);
    this.origin = origin;
    this.ranges = ranges;
    this.unit = unit;
    this.distanceType = distanceType;
    this.keyed = keyed;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:GeoDistanceRangeAggregatorFactory.java

示例7: DistanceSource

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
DistanceSource(ValuesSource.GeoPoint source, GeoDistance distanceType,
        org.elasticsearch.common.geo.GeoPoint origin, DistanceUnit units) {
    this.source = source;
    // even if the geo points are unique, there's no guarantee the
    // distances are
    this.distanceType = distanceType;
    this.units = units;
    this.origin = origin;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:GeoDistanceRangeAggregatorFactory.java

示例8: GeoDistanceAggregationBuilder

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
/**
 * Read from a stream.
 */
public GeoDistanceAggregationBuilder(StreamInput in) throws IOException {
    super(in, InternalGeoDistance.FACTORY.getValueSourceType(), InternalGeoDistance.FACTORY.getValueType());
    origin = new GeoPoint(in.readDouble(), in.readDouble());
    int size = in.readVInt();
    ranges = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        ranges.add(new Range(in));
    }
    keyed = in.readBoolean();
    distanceType = GeoDistance.readFromStream(in);
    unit = DistanceUnit.readFromStream(in);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:GeoDistanceAggregationBuilder.java

示例9: GeoDistanceSortBuilder

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
/**
 * Read from a stream.
 */
@SuppressWarnings("unchecked")
public GeoDistanceSortBuilder(StreamInput in) throws IOException {
    fieldName = in.readString();
    points.addAll((List<GeoPoint>) in.readGenericValue());
    geoDistance = GeoDistance.readFromStream(in);
    unit = DistanceUnit.readFromStream(in);
    order = SortOrder.readFromStream(in);
    sortMode = in.readOptionalWriteable(SortMode::readFromStream);
    nestedFilter = in.readOptionalNamedWriteable(QueryBuilder.class);
    nestedPath = in.readOptionalString();
    validation = GeoValidationMethod.readFromStream(in);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:GeoDistanceSortBuilder.java

示例10: parseGeoVariable

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
private AbstractDistanceScoreFunction parseGeoVariable(XContentParser parser, QueryShardContext context,
        MappedFieldType fieldType, MultiValueMode mode) throws IOException {
    XContentParser.Token token;
    String parameterName = null;
    GeoPoint origin = new GeoPoint();
    String scaleString = null;
    String offsetString = "0km";
    double decay = 0.5;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            parameterName = parser.currentName();
        } else if (DecayFunctionBuilder.SCALE.equals(parameterName)) {
            scaleString = parser.text();
        } else if (DecayFunctionBuilder.ORIGIN.equals(parameterName)) {
            origin = GeoUtils.parseGeoPoint(parser);
        } else if (DecayFunctionBuilder.DECAY.equals(parameterName)) {
            decay = parser.doubleValue();
        } else if (DecayFunctionBuilder.OFFSET.equals(parameterName)) {
            offsetString = parser.text();
        } else {
            throw new ElasticsearchParseException("parameter [{}] not supported!", parameterName);
        }
    }
    if (origin == null || scaleString == null) {
        throw new ElasticsearchParseException("[{}] and [{}] must be set for geo fields.", DecayFunctionBuilder.ORIGIN,
                DecayFunctionBuilder.SCALE);
    }
    double scale = DistanceUnit.DEFAULT.parse(scaleString, DistanceUnit.DEFAULT);
    double offset = DistanceUnit.DEFAULT.parse(offsetString, DistanceUnit.DEFAULT);
    IndexGeoPointFieldData indexFieldData = context.getForField(fieldType);
    return new GeoFieldDataScoreFunction(origin, scale, decay, offset, getDecayFunction(), indexFieldData, mode);

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:DecayFunctionBuilder.java

示例11: parse

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder(name);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = entry.getKey();
        Object fieldNode = entry.getValue();
        if (Names.TREE.equals(fieldName)) {
            builder.fieldType().setTree(fieldNode.toString());
            iterator.remove();
        } else if (Names.TREE_LEVELS.equals(fieldName)) {
            builder.fieldType().setTreeLevels(Integer.parseInt(fieldNode.toString()));
            iterator.remove();
        } else if (Names.TREE_PRESISION.equals(fieldName)) {
            builder.fieldType().setPrecisionInMeters(DistanceUnit.parse(fieldNode.toString(), DistanceUnit.DEFAULT, DistanceUnit.DEFAULT));
            iterator.remove();
        } else if (Names.DISTANCE_ERROR_PCT.equals(fieldName)) {
            builder.fieldType().setDistanceErrorPct(Double.parseDouble(fieldNode.toString()));
            iterator.remove();
        } else if (Names.ORIENTATION.equals(fieldName)) {
            builder.fieldType().setOrientation(ShapeBuilder.Orientation.fromString(fieldNode.toString()));
            iterator.remove();
        } else if (Names.STRATEGY.equals(fieldName)) {
            builder.fieldType().setStrategyName(fieldNode.toString());
            iterator.remove();
        } else if (Names.COERCE.equals(fieldName)) {
            builder.coerce(TypeParsers.nodeBooleanValue(fieldName, Names.COERCE, fieldNode, parserContext));
            iterator.remove();
        } else if (Names.STRATEGY_POINTS_ONLY.equals(fieldName)
            && builder.fieldType().strategyName.equals(SpatialStrategy.TERM.getStrategyName()) == false) {
            boolean pointsOnly = TypeParsers.nodeBooleanValue(fieldName, Names.STRATEGY_POINTS_ONLY, fieldNode, parserContext);
            builder.fieldType().setPointsOnly(pointsOnly);
            iterator.remove();
        }
    }
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:GeoShapeFieldMapper.java

示例12: doXContentBody

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
@Override
protected void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params) throws IOException {
    builder.field("type", contentType());

    if (includeDefaults || fieldType().tree().equals(Defaults.TREE) == false) {
        builder.field(Names.TREE, fieldType().tree());
    }
    if (includeDefaults || fieldType().treeLevels() != 0) {
        builder.field(Names.TREE_LEVELS, fieldType().treeLevels());
    }
    if (includeDefaults || fieldType().precisionInMeters() != -1) {
        builder.field(Names.TREE_PRESISION, DistanceUnit.METERS.toString(fieldType().precisionInMeters()));
    }
    if (includeDefaults || fieldType().strategyName() != Defaults.STRATEGY) {
        builder.field(Names.STRATEGY, fieldType().strategyName());
    }
    if (includeDefaults || fieldType().distanceErrorPct() != fieldType().defaultDistanceErrorPct) {
        builder.field(Names.DISTANCE_ERROR_PCT, fieldType().distanceErrorPct());
    }
    if (includeDefaults || fieldType().orientation() != Defaults.ORIENTATION) {
        builder.field(Names.ORIENTATION, fieldType().orientation());
    }
    if (includeDefaults || fieldType().pointsOnly() != GeoShapeFieldMapper.Defaults.POINTS_ONLY) {
        builder.field(Names.STRATEGY_POINTS_ONLY, fieldType().pointsOnly());
    }
    if (includeDefaults || coerce.explicit()) {
        builder.field("coerce", coerce.value());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:GeoShapeFieldMapper.java

示例13: createTestAggregatorBuilder

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
@Override
protected GeoDistanceAggregationBuilder createTestAggregatorBuilder() {
    int numRanges = randomIntBetween(1, 10);
    GeoPoint origin = RandomShapeGenerator.randomPoint(random());
    GeoDistanceAggregationBuilder factory = new GeoDistanceAggregationBuilder("foo", origin);
    for (int i = 0; i < numRanges; i++) {
        String key = null;
        if (randomBoolean()) {
            key = randomAsciiOfLengthBetween(1, 20);
        }
        double from = randomBoolean() ? 0 : randomIntBetween(0, Integer.MAX_VALUE - 1000);
        double to = randomBoolean() ? Double.POSITIVE_INFINITY
                : (Double.compare(from, 0) == 0 ? randomIntBetween(0, Integer.MAX_VALUE)
                        : randomIntBetween((int) from, Integer.MAX_VALUE));
        factory.addRange(new Range(key, from, to));
    }
    factory.field(randomAsciiOfLengthBetween(1, 20));
    if (randomBoolean()) {
        factory.keyed(randomBoolean());
    }
    if (randomBoolean()) {
        factory.missing("0, 0");
    }
    if (randomBoolean()) {
        factory.unit(randomFrom(DistanceUnit.values()));
    }
    if (randomBoolean()) {
        factory.distanceType(randomFrom(GeoDistance.values()));
    }
    return factory;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:GeoDistanceRangeTests.java

示例14: testCommonCaseIsOptimized

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
public void testCommonCaseIsOptimized() throws IOException {
    // make sure the below tests test something...
    assertFalse(SortField.class.equals(LatLonDocValuesField.newDistanceSort("random_field_name", 3.5, 2.1).getClass()));

    QueryShardContext context = createMockShardContext();
    // The common case should use LatLonDocValuesField.newDistanceSort
    GeoDistanceSortBuilder builder = new GeoDistanceSortBuilder("", new GeoPoint(3.5, 2.1));
    SortFieldAndFormat sort = builder.build(context);
    assertEquals(LatLonDocValuesField.newDistanceSort("random_field_name", 3.5, 2.1).getClass(), sort.field.getClass());

    // however this might be disabled by fancy options
    builder = new GeoDistanceSortBuilder("random_field_name", new GeoPoint(3.5, 2.1), new GeoPoint(3.0, 4));
    sort = builder.build(context);
    assertEquals(SortField.class, sort.field.getClass()); // 2 points -> plain SortField with a custom comparator

    builder = new GeoDistanceSortBuilder("random_field_name", new GeoPoint(3.5, 2.1));
    builder.unit(DistanceUnit.KILOMETERS);
    sort = builder.build(context);
    assertEquals(SortField.class, sort.field.getClass()); // km rather than m -> plain SortField with a custom comparator

    builder = new GeoDistanceSortBuilder("random_field_name", new GeoPoint(3.5, 2.1));
    builder.order(SortOrder.DESC);
    sort = builder.build(context);
    assertEquals(SortField.class, sort.field.getClass()); // descending means the max value should be considered rather than min

    builder = new GeoDistanceSortBuilder("random_field_name", new GeoPoint(3.5, 2.1));
    builder.setNestedPath("some_nested_path");
    sort = builder.build(context);
    assertEquals(SortField.class, sort.field.getClass()); // can't use LatLon optimized sorting with nested fields

    builder = new GeoDistanceSortBuilder("random_field_name", new GeoPoint(3.5, 2.1));
    builder.order(SortOrder.DESC);
    sort = builder.build(context);
    assertEquals(SortField.class, sort.field.getClass()); // can't use LatLon optimized sorting with DESC sorting
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:GeoDistanceSortBuilderTests.java

示例15: createRandomDecayFunction

import org.elasticsearch.common.unit.DistanceUnit; //导入依赖的package包/类
/**
 * Create a random decay function setting all of its constructor parameters randomly. The caller is responsible for randomizing other
 * fields.
 */
private static DecayFunctionBuilder<?> createRandomDecayFunction() {
    String field = randomFrom(INT_FIELD_NAME, DOUBLE_FIELD_NAME, DATE_FIELD_NAME, GEO_POINT_FIELD_NAME);
    Object origin;
    Object scale;
    Object offset;
    switch (field) {
    case GEO_POINT_FIELD_NAME:
        origin = new GeoPoint(randomDouble(), randomDouble()).geohash();
        scale = randomFrom(DistanceUnit.values()).toString(randomDouble());
        offset = randomFrom(DistanceUnit.values()).toString(randomDouble());
        break;
    case DATE_FIELD_NAME:
        origin = new DateTime(System.currentTimeMillis() - randomIntBetween(0, 1000000), DateTimeZone.UTC).toString();
        scale = randomPositiveTimeValue();
        offset = randomPositiveTimeValue();
        break;
    default:
        origin = randomBoolean() ? randomInt() : randomFloat();
        scale = randomBoolean() ? between(1, Integer.MAX_VALUE) : randomFloat() + Float.MIN_NORMAL;
        offset = randomBoolean() ? between(1, Integer.MAX_VALUE) : randomFloat() + Float.MIN_NORMAL;
        break;
    }
    offset = randomBoolean() ? null : offset;
    double decay = randomDouble();
    switch (randomIntBetween(0, 2)) {
    case 0:
        return new GaussDecayFunctionBuilder(field, origin, scale, offset, decay);
    case 1:
        return new ExponentialDecayFunctionBuilder(field, origin, scale, offset, decay);
    case 2:
        return new LinearDecayFunctionBuilder(field, origin, scale, offset, decay);
    default:
        throw new UnsupportedOperationException();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:FunctionScoreQueryBuilderTests.java


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