Merge pull request #13963 from javanna/fix/geo_shape_strategy_optional

Make strategy optional in GeoShapeQueryBuilder readFrom and writeTo
This commit is contained in:
Luca Cavanna 2015-10-06 13:23:48 +02:00
commit 84b748cae3
2 changed files with 20 additions and 13 deletions

View File

@ -70,7 +70,7 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
// and Equals so ShapeBuilder can be used here // and Equals so ShapeBuilder can be used here
private BytesReference shapeBytes; private BytesReference shapeBytes;
private SpatialStrategy strategy = null; private SpatialStrategy strategy;
private final String indexedShapeId; private final String indexedShapeId;
private final String indexedShapeType; private final String indexedShapeType;
@ -429,7 +429,9 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
} }
} }
builder.relation = ShapeRelation.DISJOINT.readFrom(in); builder.relation = ShapeRelation.DISJOINT.readFrom(in);
builder.strategy = SpatialStrategy.RECURSIVE.readFrom(in); if (in.readBoolean()) {
builder.strategy = SpatialStrategy.RECURSIVE.readFrom(in);
}
return builder; return builder;
} }
@ -447,7 +449,12 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
out.writeOptionalString(indexedShapePath); out.writeOptionalString(indexedShapePath);
} }
relation.writeTo(out); relation.writeTo(out);
strategy.writeTo(out); if (strategy == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
strategy.writeTo(out);
}
} }
@Override @Override

View File

@ -77,10 +77,12 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
builder.indexedShapePath(indexedShapePath); builder.indexedShapePath(indexedShapePath);
} }
} }
SpatialStrategy strategy = randomFrom(SpatialStrategy.values()); if (randomBoolean()) {
builder.strategy(strategy); SpatialStrategy strategy = randomFrom(SpatialStrategy.values());
if (strategy != SpatialStrategy.TERM) { builder.strategy(strategy);
builder.relation(randomFrom(ShapeRelation.values())); if (strategy != SpatialStrategy.TERM) {
builder.relation(randomFrom(ShapeRelation.values()));
}
} }
return builder; return builder;
} }
@ -105,9 +107,7 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
} catch (IOException ex) { } catch (IOException ex) {
throw new ElasticsearchException("boom", ex); throw new ElasticsearchException("boom", ex);
} }
GetResponse response = new GetResponse(new GetResult(indexedShapeIndex, indexedShapeType, indexedShapeId, 0, true, new BytesArray( return new GetResponse(new GetResult(indexedShapeIndex, indexedShapeType, indexedShapeId, 0, true, new BytesArray(json), null));
json), null));
return response;
} }
@After @After
@ -149,7 +149,7 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
@Test @Test
public void testNoShape() throws IOException { public void testNoShape() throws IOException {
try { try {
GeoShapeQueryBuilder builder = new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, (ShapeBuilder) null); new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, (ShapeBuilder) null);
fail("exception expected"); fail("exception expected");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// expected // expected
@ -158,12 +158,12 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testNoIndexedShape() throws IOException { public void testNoIndexedShape() throws IOException {
new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, (String) null, "type"); new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, null, "type");
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testNoIndexedShapeType() throws IOException { public void testNoIndexedShapeType() throws IOException {
new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, "id", (String) null); new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, "id", null);
} }
@Test(expected=IllegalArgumentException.class) @Test(expected=IllegalArgumentException.class)