protected Rectangle randomRectangle(Rectangle bounds) { double[] xNewStartAndWidth = randomSubRange(bounds.getMinX(), bounds.getWidth()); double xMin = xNewStartAndWidth[0]; double xMax = xMin + xNewStartAndWidth[1]; if (bounds.getCrossesDateLine()) { xMin = DistanceUtils.normLonDEG(xMin); xMax = DistanceUtils.normLonDEG(xMax); } double[] yNewStartAndHeight = randomSubRange(bounds.getMinY(), bounds.getHeight()); double yMin = yNewStartAndHeight[0]; double yMax = yMin + yNewStartAndHeight[1]; return ctx.makeRectangle(xMin, xMax, yMin, yMax); }
/** Constructs a query to retrieve documents that fully contain the input envelope. */ private Query makeWithin(Rectangle bbox) { BooleanQuery.Builder bq = new BooleanQuery.Builder(); BooleanClause.Occur MUST = BooleanClause.Occur.MUST; if (bbox.getCrossesDateLine()) { // use null as performance trick since no data will be beyond the world bounds bq.add(rangeQuery(fieldNameX, null /*-180*/, bbox.getMaxX()), BooleanClause.Occur.SHOULD); bq.add(rangeQuery(fieldNameX, bbox.getMinX(), null /*+180*/), BooleanClause.Occur.SHOULD); bq.setMinimumNumberShouldMatch(1); // must match at least one of the SHOULD } else { bq.add(rangeQuery(fieldNameX, bbox.getMinX(), bbox.getMaxX()), MUST); } bq.add(rangeQuery(fieldNameY, bbox.getMinY(), bbox.getMaxY()), MUST); return bq.build(); }
@Override protected GeoBoundingBoxQueryBuilder doCreateTestQueryBuilder() { GeoBoundingBoxQueryBuilder builder = new GeoBoundingBoxQueryBuilder(GEO_POINT_FIELD_NAME); Rectangle box = RandomShapeGenerator.xRandomRectangle( random(), RandomShapeGenerator.xRandomPoint(random())); if (randomBoolean()) { // check the top-left/bottom-right combination of setters int path = randomIntBetween(0, 2); switch (path) { case 0: builder.setCorners( new GeoPoint(box.getMaxY(), box.getMinX()), new GeoPoint(box.getMinY(), box.getMaxX())); break; case 1: builder.setCorners( GeohashUtils.encodeLatLon(box.getMaxY(), box.getMinX()), GeohashUtils.encodeLatLon(box.getMinY(), box.getMaxX())); break; default: builder.setCorners(box.getMaxY(), box.getMinX(), box.getMinY(), box.getMaxX()); } } else { // check the bottom-left/ top-right combination of setters if (randomBoolean()) { builder.setCornersOGC( new GeoPoint(box.getMinY(), box.getMinX()), new GeoPoint(box.getMaxY(), box.getMaxX())); } else { builder.setCornersOGC( GeohashUtils.encodeLatLon(box.getMinY(), box.getMinX()), GeohashUtils.encodeLatLon(box.getMaxY(), box.getMaxX())); } } if (randomBoolean()) { builder.setValidationMethod(randomFrom(GeoValidationMethod.values())); } if (randomBoolean()) { builder.ignoreUnmapped(randomBoolean()); } builder.type(randomFrom(GeoExecType.values())); return builder; }
protected Point randomPoint() { final Rectangle WB = ctx.getWorldBounds(); return ctx.makePoint( randomIntBetween((int) WB.getMinX(), (int) WB.getMaxX()), randomIntBetween((int) WB.getMinY(), (int) WB.getMaxY())); }