Make strategy optional in GeoShapeQueryBuilder readFrom and writeTo
The field is optional everywhere else but in the serialization methods, which causes problems. Also expanded tests so that they can catch this type of problem. Closes #13963
This commit is contained in:
parent
7b431ecc16
commit
7e840532c1
|
@ -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);
|
||||||
|
if (in.readBoolean()) {
|
||||||
builder.strategy = SpatialStrategy.RECURSIVE.readFrom(in);
|
builder.strategy = SpatialStrategy.RECURSIVE.readFrom(in);
|
||||||
|
}
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,8 +449,13 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
|
||||||
out.writeOptionalString(indexedShapePath);
|
out.writeOptionalString(indexedShapePath);
|
||||||
}
|
}
|
||||||
relation.writeTo(out);
|
relation.writeTo(out);
|
||||||
|
if (strategy == null) {
|
||||||
|
out.writeBoolean(false);
|
||||||
|
} else {
|
||||||
|
out.writeBoolean(true);
|
||||||
strategy.writeTo(out);
|
strategy.writeTo(out);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean doEquals(GeoShapeQueryBuilder other) {
|
protected boolean doEquals(GeoShapeQueryBuilder other) {
|
||||||
|
|
|
@ -77,11 +77,13 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
|
||||||
builder.indexedShapePath(indexedShapePath);
|
builder.indexedShapePath(indexedShapePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (randomBoolean()) {
|
||||||
SpatialStrategy strategy = randomFrom(SpatialStrategy.values());
|
SpatialStrategy strategy = randomFrom(SpatialStrategy.values());
|
||||||
builder.strategy(strategy);
|
builder.strategy(strategy);
|
||||||
if (strategy != SpatialStrategy.TERM) {
|
if (strategy != SpatialStrategy.TERM) {
|
||||||
builder.relation(randomFrom(ShapeRelation.values()));
|
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)
|
||||||
|
|
Loading…
Reference in New Issue