From 42b3f06a32844ade7fdf21e48f5e7e5800c31670 Mon Sep 17 00:00:00 2001 From: Florian Schilling Date: Wed, 26 Jun 2013 12:12:39 +0200 Subject: [PATCH] fixed ShapeFetchService. closes #3242 --- .../index/search/shape/ShapeFetchService.java | 1 + .../search/geo/GeoShapeIntegrationTests.java | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/main/java/org/elasticsearch/index/search/shape/ShapeFetchService.java b/src/main/java/org/elasticsearch/index/search/shape/ShapeFetchService.java index f617438f09b..58a3c192d61 100644 --- a/src/main/java/org/elasticsearch/index/search/shape/ShapeFetchService.java +++ b/src/main/java/org/elasticsearch/index/search/shape/ShapeFetchService.java @@ -73,6 +73,7 @@ public class ShapeFetchService extends AbstractComponent { parser.nextToken(); return GeoJSONShapeParser.parse(parser); } else { + parser.nextToken(); parser.skipChildren(); } } diff --git a/src/test/java/org/elasticsearch/test/integration/search/geo/GeoShapeIntegrationTests.java b/src/test/java/org/elasticsearch/test/integration/search/geo/GeoShapeIntegrationTests.java index 9eb1e1cf6dc..24b72202a5f 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/geo/GeoShapeIntegrationTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/geo/GeoShapeIntegrationTests.java @@ -25,10 +25,12 @@ import static org.elasticsearch.index.query.FilterBuilders.geoIntersectionFilter import static org.elasticsearch.index.query.QueryBuilders.filteredQuery; import static org.elasticsearch.index.query.QueryBuilders.geoShapeQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; +import java.io.IOException; import java.util.List; import java.util.Map; @@ -182,6 +184,44 @@ public class GeoShapeIntegrationTests extends AbstractSharedClusterTest { assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1")); } + @Test + public void testParsingMultipleShapes() throws IOException { + String mapping = XContentFactory.jsonBuilder() + .startObject() + .startObject("type1") + .startObject("properties") + .startObject("location1") + .field("type", "geo_shape") + .endObject() + .startObject("location2") + .field("type", "geo_shape") + .endObject() + .endObject() + .endObject() + .endObject() + .string(); + + prepareCreate("test").addMapping("type1", mapping).execute().actionGet(); + ensureYellow(); + + String p1 = "\"location1\" : {\"type\":\"polygon\", \"coordinates\":[[[-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]]]}"; + String p2 = "\"location2\" : {\"type\":\"polygon\", \"coordinates\":[[[-20,-20],[20,-20],[20,20],[-20,20],[-20,-20]]]}"; + String o1 = "{" + p1 + ", " + p2 + "}"; + + client().prepareIndex("test", "type1", "1").setSource(o1).execute().actionGet(); + client().admin().indices().prepareRefresh("test").execute().actionGet(); + + String filter = "{\"geo_shape\": {\"location2\": {\"indexed_shape\": {" + + "\"id\": \"1\"," + + "\"type\": \"type1\"," + + "\"index\": \"test\"," + + "\"shape_field_name\": \"location2\"" + + "}}}}"; + + SearchResponse result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()).setFilter(filter).execute().actionGet(); + assertHitCount(result, 1); + } + @Test // Issue 2944 public void testThatShapeIsReturnedEvenWhenExclusionsAreSet() throws Exception { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")