Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected void index(ParseContext context, Geometry geometry) throws IOException
if (geometry == null) {
return;
}
context.doc().addAll(indexer.indexShape(geometry));
context.doc().addAll(indexer.indexShape(indexer.prepareForIndexing(geometry)));
context.addToFieldNames(fieldType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,10 @@ public Geometry visit(Rectangle rectangle) {
}

public List<IndexableField> indexShape(Geometry shape) {
LuceneGeometryIndexer visitor = new LuceneGeometryIndexer(name);
shape = prepareForIndexing(shape);
if (shape == null) {
return Collections.emptyList();
}
LuceneGeometryIndexer visitor = new LuceneGeometryIndexer(name);
shape.visit(visitor);
return visitor.fields();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.geo.GeometryTestUtils;
import org.elasticsearch.geometry.Geometry;
import org.elasticsearch.geometry.LinearRing;
import org.elasticsearch.geometry.Polygon;
import org.elasticsearch.geometry.utils.WellKnownText;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.mapper.GeoShapeIndexer;
Expand Down Expand Up @@ -147,6 +149,15 @@ public void testRandomShape() throws Exception {
return true;
}
}, () -> GeometryTestUtils.randomGeometry(false)));
doTestGeometry(geometry);
}

public void testPolygonDateline() throws Exception {
Geometry geometry = new Polygon(new LinearRing(new double[]{170, 190, 190, 170, 170}, new double[]{-5, -5, 5, 5, -5}));
doTestGeometry(geometry);
}

private void doTestGeometry(Geometry geometry) throws IOException {
client().prepareIndex("test", "_doc").setId("1")
.setSource(jsonBuilder().startObject()
.field("name", "TestPosition")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ protected void index(ParseContext context, Geometry geometry) throws IOException
if (geometry == null) {
return;
}
geometry = indexer.prepareForIndexing(geometry);
List<IndexableField> fields = indexer.indexShape(geometry);
if (fieldType().isSearchable()) {
context.doc().addAll(fields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void testGeoShapeQueryAcrossDateline() throws IOException {
try (Directory dir = newDirectory(); RandomIndexWriter w = new RandomIndexWriter(random(), dir)) {
Document doc = new Document();
GeoShapeIndexer indexer = new GeoShapeIndexer(true, fieldName);
for (IndexableField field : indexer.indexShape(geometry)) {
for (IndexableField field : indexer.indexShape(indexer.prepareForIndexing(geometry))) {
doc.add(field);
}
w.addDocument(doc);
Expand Down