Map<String, Rectangle> indexedGriddedShapes = new LinkedHashMap<String, Rectangle>();
final int numIndexedShapes = randomIntBetween(1, 6);
for (int i = 1; i <= numIndexedShapes; i++) {
String id = "" + i;
Shape indexShape = randomRectangle();
Rectangle gridShape = gridSnapp(indexShape);
indexedShapes.put(id, indexShape);
indexedGriddedShapes.put(id, gridShape);
adoc(id, indexShape);
}
commit();
final int numQueryShapes = atLeast(10);
for (int i = 0; i < numQueryShapes; i++) {
int scanLevel = randomInt(grid.getMaxLevels());
((RecursivePrefixTreeStrategy) strategy).setPrefixGridScanLevel(scanLevel);
Rectangle queryShape = randomRectangle();
Rectangle queryGridShape = gridSnapp(queryShape);
//Generate truth via brute force
final SpatialOperation operation = SpatialOperation.Intersects;
Set<String> expectedIds = new TreeSet<String>();
Set<String> optionalIds = new TreeSet<String>();
for (String id : indexedShapes.keySet()) {
Shape indexShape = indexedShapes.get(id);
Rectangle indexGridShape = indexedGriddedShapes.get(id);
if (operation.evaluate(indexShape, queryShape))
expectedIds.add(id);
else if (operation.evaluate(indexGridShape, queryGridShape))
optionalIds.add(id);
}