GeoShapeCondition extends GeospatialCondition { @Override public Query doQuery(SpatialStrategy strategy) { SpatialArgs args = new SpatialArgs(operation.getSpatialOperation(), shape.apply()); args.setDistErr(0.0); return strategy.makeQuery(args); } GeoShapeCondition(Float boost, String field, GeoShape shape, GeoOperation operation); @Override Query doQuery(SpatialStrategy strategy); @Override MoreObjects.ToStringHelper toStringHelper(); static final GeoOperation DEFAULT_OPERATION; final GeoShape shape; final GeoOperation operation; }
@Test(expected = IndexException.class) public void testQueryWithInvalidGeometry() { Schema schema = schema().mapper("geo_point", geoPointMapper("lat", "lon").maxLevels(8)).build(); GeoShape shape = new GeoShape.WKT("POLYGONS((1 1,5 1,5 5,1 5,1 1))"); Condition condition = new GeoShapeCondition(null, "geo_point", shape, null); condition.doQuery(schema); }
@Test public void testQueryIsWithIn() { Schema schema = schema().mapper("geo_point", geoPointMapper("lat", "lon").maxLevels(8)).build(); Condition condition = new GeoShapeCondition(0.1f, "geo_point", SHAPE, GeoOperation.IS_WITHIN); Query query = condition.doQuery(schema); assertNotNull("Query is not built", query); assertEquals("Query type is wrong", CompositeVerifyQuery.class, query.getClass()); assertTrue("Query is wrong", query.toString() .startsWith("CompositeVerifyQuery(IntersectsPrefixTreeQuery(fieldName=geo_point,queryShape=")); }
@Test public void testQueryIntersects() { Schema schema = schema().mapper("geo_point", geoPointMapper("lat", "lon").maxLevels(8)).build(); Condition condition = new GeoShapeCondition(0.1f, "geo_point", SHAPE, GeoOperation.INTERSECTS); Query query = condition.doQuery(schema); assertNotNull("Query is not built", query); assertEquals("Query type is wrong", IntersectsRPTVerifyQuery.class, query.getClass()); assertEquals("Query is wrong", "IntersectsVerified(fieldName=)", query.toString()); }
@Test public void testQueryContains() { Schema schema = schema().mapper("geo_point", geoPointMapper("lat", "lon").maxLevels(8)).build(); Condition condition = new GeoShapeCondition(0.1f, "geo_point", SHAPE, GeoOperation.CONTAINS); Query query = condition.doQuery(schema); assertNotNull("Query is not built", query); assertEquals("Query type is wrong", CompositeVerifyQuery.class, query.getClass()); assertTrue("Query is wrong", query.toString() .startsWith("CompositeVerifyQuery(ContainsPrefixTreeQuery(fieldName=geo_point,queryShape=")); }