use of org.opensearch.common.geo.builders.EnvelopeBuilder in project OpenSearch by opensearch-project.
the class GeoShapeQueryBuilderTests method testThatXContentSerializationInsideOfArrayWorks.
// see #3878
public void testThatXContentSerializationInsideOfArrayWorks() throws Exception {
EnvelopeBuilder envelopeBuilder = new EnvelopeBuilder(new Coordinate(0, 10), new Coordinate(10, 0));
GeoShapeQueryBuilder geoQuery = randomBoolean() ? QueryBuilders.geoShapeQuery("searchGeometry", envelopeBuilder) : QueryBuilders.geoShapeQuery("searchGeometry", envelopeBuilder.buildGeometry());
JsonXContent.contentBuilder().startArray().value(geoQuery).endArray();
}
use of org.opensearch.common.geo.builders.EnvelopeBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testNewRectangle.
public void testNewRectangle() {
EnvelopeBuilder eb = new EnvelopeBuilder(new Coordinate(-45, 30), new Coordinate(45, -30));
Rectangle rectangle = eb.buildS4J();
assertEquals(-45D, rectangle.getMinX(), 0.0d);
assertEquals(-30D, rectangle.getMinY(), 0.0d);
assertEquals(45D, rectangle.getMaxX(), 0.0d);
assertEquals(30D, rectangle.getMaxY(), 0.0d);
org.opensearch.geometry.Rectangle luceneRectangle = eb.buildGeometry();
assertEquals(-45D, luceneRectangle.getMinX(), 0.0d);
assertEquals(-30D, luceneRectangle.getMinY(), 0.0d);
assertEquals(45D, luceneRectangle.getMaxX(), 0.0d);
assertEquals(30D, luceneRectangle.getMaxY(), 0.0d);
}
use of org.opensearch.common.geo.builders.EnvelopeBuilder in project OpenSearch by opensearch-project.
the class GeoWKTShapeParserTests method testParseEnvelope.
@Override
public void testParseEnvelope() throws IOException, ParseException {
org.apache.lucene.geo.Rectangle r = GeoTestUtil.nextBox();
EnvelopeBuilder builder = new EnvelopeBuilder(new Coordinate(r.minLon, r.maxLat), new Coordinate(r.maxLon, r.minLat));
Rectangle expected = SPATIAL_CONTEXT.makeRectangle(r.minLon, r.maxLon, r.minLat, r.maxLat);
assertExpected(expected, builder, true);
assertExpected(new org.opensearch.geometry.Rectangle(r.minLon, r.maxLon, r.maxLat, r.minLat), builder, false);
assertMalformed(builder);
}
use of org.opensearch.common.geo.builders.EnvelopeBuilder in project OpenSearch by opensearch-project.
the class GeoShapeQueryTests method testIndexedShapeReferenceSourceDisabled.
public void testIndexedShapeReferenceSourceDisabled() throws Exception {
XContentBuilder mapping = createDefaultMapping();
client().admin().indices().prepareCreate("test").addMapping("type1", mapping).get();
createIndex("shapes", Settings.EMPTY, "shape_type", "_source", "enabled=false");
ensureGreen();
EnvelopeBuilder shape = new EnvelopeBuilder(new Coordinate(-45, 45), new Coordinate(45, -45));
client().prepareIndex("shapes").setId("Big_Rectangle").setSource(jsonBuilder().startObject().field("shape", shape).endObject()).setRefreshPolicy(IMMEDIATE).get();
try {
client().prepareSearch("test").setQuery(geoIntersectionQuery("geo", "Big_Rectangle")).get();
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("source disabled"));
}
}
use of org.opensearch.common.geo.builders.EnvelopeBuilder in project OpenSearch by opensearch-project.
the class GeoShapeQueryTests method testIndexRectangleSpanningDateLine.
public void testIndexRectangleSpanningDateLine() throws Exception {
String mapping = Strings.toString(createRandomMapping());
client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).get();
ensureGreen();
EnvelopeBuilder envelopeBuilder = new EnvelopeBuilder(new Coordinate(178, 10), new Coordinate(-178, -10));
XContentBuilder docSource = envelopeBuilder.toXContent(jsonBuilder().startObject().field("geo"), null).endObject();
client().prepareIndex("test").setId("1").setSource(docSource).setRefreshPolicy(IMMEDIATE).get();
ShapeBuilder filterShape = new PointBuilder(179, 0);
GeoShapeQueryBuilder geoShapeQueryBuilder = QueryBuilders.geoShapeQuery("geo", filterShape);
geoShapeQueryBuilder.relation(ShapeRelation.INTERSECTS);
SearchResponse result = client().prepareSearch("test").setQuery(geoShapeQueryBuilder).get();
assertSearchResponse(result);
assertHitCount(result, 1);
}
Aggregations