Java 类org.apache.lucene.document.LatLonPoint 实例源码

项目:elasticsearch_my    文件:GeoDistanceQueryBuilderTests.java   
@Override
protected void doAssertLuceneQuery(GeoDistanceQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException {
    // TODO: remove the if statement once we always use LatLonPoint
    if (query instanceof IndexOrDocValuesQuery) {
        Query indexQuery = ((IndexOrDocValuesQuery) query).getIndexQuery();
        assertEquals(LatLonPoint.newDistanceQuery(queryBuilder.fieldName(),
                queryBuilder.point().lat(),
                queryBuilder.point().lon(),
                queryBuilder.distance()),
                indexQuery);
        Query dvQuery = ((IndexOrDocValuesQuery) query).getRandomAccessQuery();
        assertEquals(LatLonDocValuesField.newDistanceQuery(queryBuilder.fieldName(),
                queryBuilder.point().lat(),
                queryBuilder.point().lon(),
                queryBuilder.distance()),
                dvQuery);
    }
}
项目:elasticsearch_my    文件:GeoBoundingBoxQueryBuilderTests.java   
@Override
protected void doAssertLuceneQuery(GeoBoundingBoxQueryBuilder queryBuilder, Query query, SearchContext searchContext)
    throws IOException {
    QueryShardContext context = searchContext.getQueryShardContext();
    MappedFieldType fieldType = context.fieldMapper(queryBuilder.fieldName());
    if (fieldType == null) {
        assertTrue("Found no indexed geo query.", query instanceof MatchNoDocsQuery);
    } else if (query instanceof IndexOrDocValuesQuery) { // TODO: remove the if statement once we always use LatLonPoint
        Query indexQuery = ((IndexOrDocValuesQuery) query).getIndexQuery();
        assertEquals(LatLonPoint.newBoxQuery(queryBuilder.fieldName(),
                queryBuilder.bottomRight().lat(),
                queryBuilder.topLeft().lat(),
                queryBuilder.topLeft().lon(),
                queryBuilder.bottomRight().lon()), indexQuery);
        Query dvQuery = ((IndexOrDocValuesQuery) query).getRandomAccessQuery();
        assertEquals(LatLonDocValuesField.newBoxQuery(queryBuilder.fieldName(),
                queryBuilder.bottomRight().lat(),
                queryBuilder.topLeft().lat(),
                queryBuilder.topLeft().lon(),
                queryBuilder.bottomRight().lon()), dvQuery);
    }
}
项目:elasticsearch_my    文件:GeoDistanceQueryBuilder.java   
@Override
protected Query doToQuery(QueryShardContext shardContext) throws IOException {
    MappedFieldType fieldType = shardContext.fieldMapper(fieldName);
    if (fieldType == null) {
        if (ignoreUnmapped) {
            return new MatchNoDocsQuery();
        } else {
            throw new QueryShardException(shardContext, "failed to find geo_point field [" + fieldName + "]");
        }
    }

    if (!(fieldType instanceof GeoPointFieldType)) {
        throw new QueryShardException(shardContext, "field [" + fieldName + "] is not a geo_point field");
    }

    final Version indexVersionCreated = shardContext.indexVersionCreated();
    QueryValidationException exception = checkLatLon(shardContext.indexVersionCreated().before(Version.V_2_0_0));
    if (exception != null) {
        throw new QueryShardException(shardContext, "couldn't validate latitude/ longitude values", exception);
    }

    if (indexVersionCreated.onOrAfter(Version.V_2_2_0) || GeoValidationMethod.isCoerce(validationMethod)) {
        GeoUtils.normalizePoint(center, true, true);
    }

    Query query = LatLonPoint.newDistanceQuery(fieldType.name(), center.lat(), center.lon(), this.distance);
    if (fieldType.hasDocValues()) {
        Query dvQuery = LatLonDocValuesField.newDistanceQuery(fieldType.name(), center.lat(), center.lon(), this.distance);
        query = new IndexOrDocValuesQuery(query, dvQuery);
    }
    return query;
}
项目:elasticsearch_my    文件:GeoPointFieldMapper.java   
protected void parse(ParseContext originalContext, GeoPoint point) throws IOException {
    // Geopoint fields, by default, will not be included in _all
    final ParseContext context = originalContext.setIncludeInAllDefault(false);

    if (ignoreMalformed.value() == false) {
        if (point.lat() > 90.0 || point.lat() < -90.0) {
            throw new IllegalArgumentException("illegal latitude value [" + point.lat() + "] for " + name());
        }
        if (point.lon() > 180.0 || point.lon() < -180) {
            throw new IllegalArgumentException("illegal longitude value [" + point.lon() + "] for " + name());
        }
    } else {
        GeoUtils.normalizePoint(point);
    }
    if (fieldType().indexOptions() != IndexOptions.NONE) {
        context.doc().add(new LatLonPoint(fieldType().name(), point.lat(), point.lon()));
    }
    if (fieldType().stored()) {
        context.doc().add(new StoredField(fieldType().name(), point.toString()));
    }
    if (fieldType.hasDocValues()) {
        context.doc().add(new LatLonDocValuesField(fieldType().name(), point.lat(), point.lon()));
    }
    // if the mapping contains multifields then use the geohash string
    if (multiFields.iterator().hasNext()) {
        multiFields.parse(this, context.createExternalValueContext(point.geohash()));
    }
}
项目:elasticsearch_my    文件:GeoPoint.java   
public GeoPoint resetFromIndexableField(IndexableField field) {
    if (field instanceof LatLonPoint) {
        BytesRef br = field.binaryValue();
        byte[] bytes = Arrays.copyOfRange(br.bytes, br.offset, br.length);
        return this.reset(
            GeoEncodingUtils.decodeLatitude(bytes, 0),
            GeoEncodingUtils.decodeLongitude(bytes, Integer.BYTES));
    } else if (field instanceof LatLonDocValuesField) {
        long encoded = (long)(field.numericValue());
        return this.reset(
            GeoEncodingUtils.decodeLatitude((int)(encoded >>> 32)),
            GeoEncodingUtils.decodeLongitude((int)encoded));
    }
    return resetFromIndexHash(Long.parseLong(field.stringValue()));
}
项目:para    文件:LuceneUtils.java   
private static Field getField(String field, String value) {
    if ("latlng".equals(field) && StringUtils.contains(value, ",")) {
        String[] latlng = value.split(",", 2);
        return new LatLonPoint(field, NumberUtils.toDouble(latlng[0]), NumberUtils.toDouble(latlng[1]));
    } else if (Config._ID.equals(field)) {
        return new Field(field, value, ID_FIELD);
    } else {
        if (NOT_ANALYZED_FIELDS.contains(field)) {
            return new Field(field, value, DEFAULT_NOT_ANALYZED_FIELD);
        } else {
            return new Field(field, value, DEFAULT_FIELD);
        }
    }
}