From 9077bb6528f843ca8042ff95f8fac47140ef5aa1 Mon Sep 17 00:00:00 2001 From: kimchy Date: Wed, 13 Oct 2010 03:35:35 +0200 Subject: [PATCH] Geo Overhaul (work with multiple locations), closes #414. Change (again) how geo location is stored, not using geohash but explicit double conversion --- .../xcontent/geo/GeoPointFieldData.java | 9 +- .../xcontent/geo/GeoPointFieldMapper.java | 69 +++++++++----- .../geopoint/GeohashMappingGeoPointTests.java | 7 +- .../LatLonAndGeohashMappingGeoPointTests.java | 90 +++++++++++++++++++ .../geopoint/LatLonMappingGeoPointTests.java | 28 +++--- 5 files changed, 161 insertions(+), 42 deletions(-) create mode 100644 modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/geopoint/LatLonAndGeohashMappingGeoPointTests.java diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/geo/GeoPointFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/geo/GeoPointFieldData.java index a8d7f95f676..cc0b8cbb25d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/geo/GeoPointFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/geo/GeoPointFieldData.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.mapper.xcontent.geo; import org.apache.lucene.index.IndexReader; -import org.elasticsearch.common.lucene.geo.GeoHashUtils; import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.field.data.support.FieldDataLoader; @@ -86,8 +85,6 @@ public abstract class GeoPointFieldData extends FieldData private final ArrayList terms = new ArrayList(); - private final double[] latlon = new double[2]; - StringTypeLoader() { super(); // the first one indicates null value @@ -95,8 +92,10 @@ public abstract class GeoPointFieldData extends FieldData } @Override public void collectTerm(String term) { - GeoHashUtils.decode(term, latlon); - terms.add(new GeoPoint(latlon[0], latlon[1])); + int comma = term.indexOf(','); + double lat = Double.parseDouble(term.substring(0, comma)); + double lon = Double.parseDouble(term.substring(comma + 1)); + terms.add(new GeoPoint(lat, lon)); } @Override public GeoPointFieldData buildSingleValue(String field, int[] order) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/geo/GeoPointFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/geo/GeoPointFieldMapper.java index 43bc40b3d38..227ab6ede2b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/geo/GeoPointFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/geo/GeoPointFieldMapper.java @@ -72,6 +72,8 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars private ContentPath.Type pathType = Defaults.PATH_TYPE; + private boolean enableGeoHash = false; + private boolean enableLatLon = false; private Integer precisionStep; @@ -90,6 +92,11 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars return this; } + public Builder enableGeoHash(boolean enableGeoHash) { + this.enableGeoHash = enableGeoHash; + return this; + } + public Builder enableLatLon(boolean enableLatLon) { this.enableLatLon = enableLatLon; return this; @@ -114,7 +121,7 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars ContentPath.Type origPathType = context.path().pathType(); context.path().pathType(pathType); - GeoHashFieldMapper geohashMapper = new GeoHashFieldMapper.Builder(name) + GeoStringFieldMapper geoStringMapper = new GeoStringFieldMapper.Builder(name) .index(Field.Index.NOT_ANALYZED).omitNorms(true).omitTermFreqAndPositions(true).includeInAll(false).store(store).build(context); @@ -132,11 +139,15 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars latMapper = (NumberFieldMapper) latMapperBuilder.includeInAll(false).store(store).build(context); lonMapper = (NumberFieldMapper) lonMapperBuilder.includeInAll(false).store(store).build(context); } + StringFieldMapper geohashMapper = null; + if (enableGeoHash) { + geohashMapper = stringField(Names.GEOHASH).index(Field.Index.NOT_ANALYZED).includeInAll(false).omitNorms(true).omitTermFreqAndPositions(true).build(context); + } context.path().remove(); context.path().pathType(origPathType); - return new GeoPointFieldMapper(name, pathType, enableLatLon, precisionStep, precision, latMapper, lonMapper, geohashMapper); + return new GeoPointFieldMapper(name, pathType, enableLatLon, enableGeoHash, precisionStep, precision, latMapper, lonMapper, geohashMapper, geoStringMapper); } } @@ -153,9 +164,11 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars builder.store(parseStore(name, fieldNode.toString())); } else if (fieldName.equals("lat_lon")) { builder.enableLatLon(XContentMapValues.nodeBooleanValue(fieldNode)); + } else if (fieldName.equals("geohash")) { + builder.enableGeoHash(XContentMapValues.nodeBooleanValue(fieldNode)); } else if (fieldName.equals("precision_step")) { builder.precisionStep(XContentMapValues.nodeIntegerValue(fieldNode)); - } else if (fieldName.equals("precision")) { + } else if (fieldName.equals("geohash_precision")) { builder.precision(XContentMapValues.nodeIntegerValue(fieldNode)); } } @@ -169,6 +182,8 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars private final boolean enableLatLon; + private final boolean enableGeoHash; + private final Integer precisionStep; private final int precision; @@ -179,16 +194,20 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars private final StringFieldMapper geohashMapper; - public GeoPointFieldMapper(String name, ContentPath.Type pathType, boolean enableLatLon, Integer precisionStep, int precision, - NumberFieldMapper latMapper, NumberFieldMapper lonMapper, StringFieldMapper geohashMapper) { + private final StringFieldMapper geoStringMapper; + + public GeoPointFieldMapper(String name, ContentPath.Type pathType, boolean enableLatLon, boolean enableGeoHash, Integer precisionStep, int precision, + NumberFieldMapper latMapper, NumberFieldMapper lonMapper, StringFieldMapper geohashMapper, StringFieldMapper geoStringMapper) { this.name = name; this.pathType = pathType; this.enableLatLon = enableLatLon; + this.enableGeoHash = enableGeoHash; this.precisionStep = precisionStep; this.precision = precision; this.latMapper = latMapper; this.lonMapper = lonMapper; + this.geoStringMapper = geoStringMapper; this.geohashMapper = geohashMapper; } @@ -287,8 +306,12 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars } private void parseLatLon(ParseContext context, Double lat, Double lon) throws IOException { - context.externalValue(GeoHashUtils.encode(lat, lon, precision)); - geohashMapper.parse(context); + context.externalValue(lat.toString() + ',' + lon.toString()); + geoStringMapper.parse(context); + if (enableGeoHash) { + context.externalValue(GeoHashUtils.encode(lat, lon, precision)); + geohashMapper.parse(context); + } if (enableLatLon) { context.externalValue(lat); latMapper.parse(context); @@ -298,10 +321,14 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars } private void parseGeohash(ParseContext context, String geohash) throws IOException { - context.externalValue(geohash); - geohashMapper.parse(context); + double[] values = GeoHashUtils.decode(geohash); + context.externalValue(Double.toString(values[0]) + ',' + Double.toString(values[1])); + geoStringMapper.parse(context); + if (enableGeoHash) { + context.externalValue(geohash); + geohashMapper.parse(context); + } if (enableLatLon) { - double[] values = GeoHashUtils.decode(geohash); context.externalValue(values[0]); latMapper.parse(context); context.externalValue(values[1]); @@ -314,7 +341,10 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars } @Override public void traverse(FieldMapperListener fieldMapperListener) { - geohashMapper.traverse(fieldMapperListener); + geoStringMapper.traverse(fieldMapperListener); + if (enableGeoHash) { + geohashMapper.traverse(fieldMapperListener); + } if (enableLatLon) { latMapper.traverse(fieldMapperListener); lonMapper.traverse(fieldMapperListener); @@ -326,12 +356,9 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars builder.field("type", CONTENT_TYPE); builder.field("path", pathType.name().toLowerCase()); builder.field("lat_lon", enableLatLon); - if (latMapper != null) { - builder.field("store", latMapper.store().name().toLowerCase()); - } else if (geohashMapper != null) { - builder.field("store", geohashMapper.store().name().toLowerCase()); - } - builder.field("precision", precision); + builder.field("geohash", enableGeoHash); + builder.field("store", geoStringMapper.store().name().toLowerCase()); + builder.field("geohash_precision", precision); if (precisionStep != null) { builder.field("precision_step", precisionStep); } @@ -339,7 +366,7 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars builder.endObject(); } - public static class GeoHashFieldMapper extends StringFieldMapper { + public static class GeoStringFieldMapper extends StringFieldMapper { public static class Builder extends AbstractFieldMapper.OpenBuilder { @@ -360,8 +387,8 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars return this; } - @Override public GeoHashFieldMapper build(BuilderContext context) { - GeoHashFieldMapper fieldMapper = new GeoHashFieldMapper(buildNames(context), + @Override public GeoStringFieldMapper build(BuilderContext context) { + GeoStringFieldMapper fieldMapper = new GeoStringFieldMapper(buildNames(context), index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, nullValue, indexAnalyzer, searchAnalyzer); fieldMapper.includeInAll(includeInAll); @@ -369,7 +396,7 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars } } - public GeoHashFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector, float boost, boolean omitNorms, boolean omitTermFreqAndPositions, String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) { + public GeoStringFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector, float boost, boolean omitNorms, boolean omitTermFreqAndPositions, String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) { super(names, index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, nullValue, indexAnalyzer, searchAnalyzer); } diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/geopoint/GeohashMappingGeoPointTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/geopoint/GeohashMappingGeoPointTests.java index 026a49b550f..14521df7775 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/geopoint/GeohashMappingGeoPointTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/geopoint/GeohashMappingGeoPointTests.java @@ -49,7 +49,7 @@ public class GeohashMappingGeoPointTests { MatcherAssert.assertThat(doc.doc().getField("point.lat"), nullValue()); MatcherAssert.assertThat(doc.doc().getField("point.lon"), nullValue()); - MatcherAssert.assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + MatcherAssert.assertThat(doc.doc().get("point"), equalTo("1.2,1.3")); } @Test public void testLatLonInOneValue() throws Exception { @@ -67,7 +67,7 @@ public class GeohashMappingGeoPointTests { MatcherAssert.assertThat(doc.doc().getField("point.lat"), nullValue()); MatcherAssert.assertThat(doc.doc().getField("point.lon"), nullValue()); - MatcherAssert.assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + MatcherAssert.assertThat(doc.doc().get("point"), equalTo("1.2,1.3")); } @Test public void testGeoHashValue() throws Exception { @@ -85,6 +85,7 @@ public class GeohashMappingGeoPointTests { MatcherAssert.assertThat(doc.doc().getField("point.lat"), nullValue()); MatcherAssert.assertThat(doc.doc().getField("point.lon"), nullValue()); - MatcherAssert.assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + MatcherAssert.assertThat(doc.doc().get("point.geohash"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + MatcherAssert.assertThat(doc.doc().get("point"), notNullValue()); } } diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/geopoint/LatLonAndGeohashMappingGeoPointTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/geopoint/LatLonAndGeohashMappingGeoPointTests.java new file mode 100644 index 00000000000..f4f43e15115 --- /dev/null +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/geopoint/LatLonAndGeohashMappingGeoPointTests.java @@ -0,0 +1,90 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.mapper.xcontent.geopoint; + +import org.elasticsearch.common.lucene.geo.GeoHashUtils; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.index.mapper.ParsedDocument; +import org.elasticsearch.index.mapper.xcontent.MapperTests; +import org.elasticsearch.index.mapper.xcontent.XContentDocumentMapper; +import org.hamcrest.MatcherAssert; +import org.testng.annotations.Test; + +import static org.hamcrest.Matchers.*; + +/** + * @author kimchy (shay.banon) + */ +public class LatLonAndGeohashMappingGeoPointTests { + + @Test public void testLatLonValues() throws Exception { + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true).endObject().endObject() + .endObject().endObject().string(); + + XContentDocumentMapper defaultMapper = MapperTests.newParser().parse(mapping); + + ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder() + .startObject() + .startObject("point").field("lat", 1.2).field("lon", 1.3).endObject() + .endObject() + .copiedBytes()); + + MatcherAssert.assertThat(doc.doc().getField("point.lat"), notNullValue()); + MatcherAssert.assertThat(doc.doc().getField("point.lon"), notNullValue()); + MatcherAssert.assertThat(doc.doc().get("point.geohash"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + } + + @Test public void testLatLonInOneValue() throws Exception { + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true).endObject().endObject() + .endObject().endObject().string(); + + XContentDocumentMapper defaultMapper = MapperTests.newParser().parse(mapping); + + ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder() + .startObject() + .field("point", "1.2,1.3") + .endObject() + .copiedBytes()); + + MatcherAssert.assertThat(doc.doc().getField("point.lat"), notNullValue()); + MatcherAssert.assertThat(doc.doc().getField("point.lon"), notNullValue()); + MatcherAssert.assertThat(doc.doc().get("point.geohash"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + } + + @Test public void testGeoHashValue() throws Exception { + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true).endObject().endObject() + .endObject().endObject().string(); + + XContentDocumentMapper defaultMapper = MapperTests.newParser().parse(mapping); + + ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder() + .startObject() + .field("point", GeoHashUtils.encode(1.2, 1.3)) + .endObject() + .copiedBytes()); + + MatcherAssert.assertThat(doc.doc().getField("point.lat"), notNullValue()); + MatcherAssert.assertThat(doc.doc().getField("point.lon"), notNullValue()); + MatcherAssert.assertThat(doc.doc().get("point.geohash"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/geopoint/LatLonMappingGeoPointTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/geopoint/LatLonMappingGeoPointTests.java index f3bbac7cc6f..e66897d6b41 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/geopoint/LatLonMappingGeoPointTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/geopoint/LatLonMappingGeoPointTests.java @@ -52,7 +52,8 @@ public class LatLonMappingGeoPointTests { assertThat(doc.doc().getField("point.lat").getBinaryValue(), nullValue()); assertThat(doc.doc().getField("point.lon"), notNullValue()); assertThat(doc.doc().getField("point.lon").getBinaryValue(), nullValue()); - assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + assertThat(doc.doc().getField("point.geohash"), nullValue()); + assertThat(doc.doc().get("point"), equalTo("1.2,1.3")); } @Test public void testLatLonValuesStored() throws Exception { @@ -72,7 +73,8 @@ public class LatLonMappingGeoPointTests { assertThat(doc.doc().getField("point.lat").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2))); assertThat(doc.doc().getField("point.lon"), notNullValue()); assertThat(doc.doc().getField("point.lon").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3))); - assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + assertThat(doc.doc().getField("point.geohash"), nullValue()); + assertThat(doc.doc().get("point"), equalTo("1.2,1.3")); } @Test public void testArrayLatLonValues() throws Exception { @@ -95,10 +97,10 @@ public class LatLonMappingGeoPointTests { assertThat(doc.doc().getFields("point.lon").length, equalTo(2)); assertThat(doc.doc().getFields("point.lat")[0].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2))); assertThat(doc.doc().getFields("point.lon")[0].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3))); - assertThat(doc.doc().getFields("point")[0].stringValue(), equalTo(GeoHashUtils.encode(1.2, 1.3))); + assertThat(doc.doc().getFields("point")[0].stringValue(), equalTo("1.2,1.3")); assertThat(doc.doc().getFields("point.lat")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.4))); assertThat(doc.doc().getFields("point.lon")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.5))); - assertThat(doc.doc().getFields("point")[1].stringValue(), equalTo(GeoHashUtils.encode(1.4, 1.5))); + assertThat(doc.doc().getFields("point")[1].stringValue(), equalTo("1.4,1.5")); } @Test public void testLatLonInOneValue() throws Exception { @@ -116,7 +118,7 @@ public class LatLonMappingGeoPointTests { assertThat(doc.doc().getField("point.lat"), notNullValue()); assertThat(doc.doc().getField("point.lon"), notNullValue()); - assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + assertThat(doc.doc().get("point"), equalTo("1.2,1.3")); } @Test public void testLatLonInOneValueStored() throws Exception { @@ -136,7 +138,7 @@ public class LatLonMappingGeoPointTests { assertThat(doc.doc().getField("point.lat").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2))); assertThat(doc.doc().getField("point.lon"), notNullValue()); assertThat(doc.doc().getField("point.lon").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3))); - assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + assertThat(doc.doc().get("point"), equalTo("1.2,1.3")); } @Test public void testLatLonInOneValueArray() throws Exception { @@ -159,10 +161,10 @@ public class LatLonMappingGeoPointTests { assertThat(doc.doc().getFields("point.lon").length, equalTo(2)); assertThat(doc.doc().getFields("point.lat")[0].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2))); assertThat(doc.doc().getFields("point.lon")[0].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3))); - assertThat(doc.doc().getFields("point")[0].stringValue(), equalTo(GeoHashUtils.encode(1.2, 1.3))); + assertThat(doc.doc().getFields("point")[0].stringValue(), equalTo("1.2,1.3")); assertThat(doc.doc().getFields("point.lat")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.4))); assertThat(doc.doc().getFields("point.lon")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.5))); - assertThat(doc.doc().getFields("point")[1].stringValue(), equalTo(GeoHashUtils.encode(1.4, 1.5))); + assertThat(doc.doc().getFields("point")[1].stringValue(), equalTo("1.4,1.5")); } @Test public void testGeoHashValue() throws Exception { @@ -180,7 +182,7 @@ public class LatLonMappingGeoPointTests { assertThat(doc.doc().getField("point.lat"), notNullValue()); assertThat(doc.doc().getField("point.lon"), notNullValue()); - assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + assertThat(doc.doc().get("point"), notNullValue()); } @Test public void testLatLonArray() throws Exception { @@ -200,7 +202,7 @@ public class LatLonMappingGeoPointTests { assertThat(doc.doc().getField("point.lat").getBinaryValue(), nullValue()); assertThat(doc.doc().getField("point.lon"), notNullValue()); assertThat(doc.doc().getField("point.lon").getBinaryValue(), nullValue()); - assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + assertThat(doc.doc().get("point"), equalTo("1.2,1.3")); } @Test public void testLatLonArrayStored() throws Exception { @@ -220,7 +222,7 @@ public class LatLonMappingGeoPointTests { assertThat(doc.doc().getField("point.lat").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2))); assertThat(doc.doc().getField("point.lon"), notNullValue()); assertThat(doc.doc().getField("point.lon").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3))); - assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3))); + assertThat(doc.doc().get("point"), equalTo("1.2,1.3")); } @Test public void testLatLonArrayArrayStored() throws Exception { @@ -243,9 +245,9 @@ public class LatLonMappingGeoPointTests { assertThat(doc.doc().getFields("point.lon").length, equalTo(2)); assertThat(doc.doc().getFields("point.lat")[0].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2))); assertThat(doc.doc().getFields("point.lon")[0].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3))); - assertThat(doc.doc().getFields("point")[0].stringValue(), equalTo(GeoHashUtils.encode(1.2, 1.3))); + assertThat(doc.doc().getFields("point")[0].stringValue(), equalTo("1.2,1.3")); assertThat(doc.doc().getFields("point.lat")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.4))); assertThat(doc.doc().getFields("point.lon")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.5))); - assertThat(doc.doc().getFields("point")[1].stringValue(), equalTo(GeoHashUtils.encode(1.4, 1.5))); + assertThat(doc.doc().getFields("point")[1].stringValue(), equalTo("1.4,1.5")); } }