Skip to content

Make strategy optional in GeoShapeQueryBuilder readFrom and writeTo #13963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2015
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 @@ -70,7 +70,7 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
// and Equals so ShapeBuilder can be used here
private BytesReference shapeBytes;

private SpatialStrategy strategy = null;
private SpatialStrategy strategy;

private final String indexedShapeId;
private final String indexedShapeType;
Expand Down Expand Up @@ -429,7 +429,9 @@ protected GeoShapeQueryBuilder doReadFrom(StreamInput in) throws IOException {
}
}
builder.relation = ShapeRelation.DISJOINT.readFrom(in);
builder.strategy = SpatialStrategy.RECURSIVE.readFrom(in);
if (in.readBoolean()) {
builder.strategy = SpatialStrategy.RECURSIVE.readFrom(in);
}
return builder;
}

Expand All @@ -447,7 +449,12 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeOptionalString(indexedShapePath);
}
relation.writeTo(out);
strategy.writeTo(out);
if (strategy == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
strategy.writeTo(out);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ protected GeoShapeQueryBuilder doCreateTestQueryBuilder() {
builder.indexedShapePath(indexedShapePath);
}
}
SpatialStrategy strategy = randomFrom(SpatialStrategy.values());
builder.strategy(strategy);
if (strategy != SpatialStrategy.TERM) {
builder.relation(randomFrom(ShapeRelation.values()));
if (randomBoolean()) {
SpatialStrategy strategy = randomFrom(SpatialStrategy.values());
builder.strategy(strategy);
if (strategy != SpatialStrategy.TERM) {
builder.relation(randomFrom(ShapeRelation.values()));
}
}
return builder;
}
Expand All @@ -105,9 +107,7 @@ protected GetResponse executeGet(GetRequest getRequest) {
} catch (IOException ex) {
throw new ElasticsearchException("boom", ex);
}
GetResponse response = new GetResponse(new GetResult(indexedShapeIndex, indexedShapeType, indexedShapeId, 0, true, new BytesArray(
json), null));
return response;
return new GetResponse(new GetResult(indexedShapeIndex, indexedShapeType, indexedShapeId, 0, true, new BytesArray(json), null));
}

@After
Expand Down Expand Up @@ -149,7 +149,7 @@ public void testNoFieldName() throws Exception {
@Test
public void testNoShape() throws IOException {
try {
GeoShapeQueryBuilder builder = new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, (ShapeBuilder) null);
new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, (ShapeBuilder) null);
fail("exception expected");
} catch (IllegalArgumentException e) {
// expected
Expand All @@ -158,12 +158,12 @@ public void testNoShape() throws IOException {

@Test(expected = IllegalArgumentException.class)
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)
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)
Expand Down