@Override public ConstantScoreQuery makeQuery(SpatialArgs args) { if (!SpatialOperation.is( args.getOperation(), SpatialOperation.Intersects, SpatialOperation.IsWithin)) throw new UnsupportedSpatialOperation(args.getOperation()); Shape shape = args.getShape(); if (shape instanceof Rectangle) { Rectangle bbox = (Rectangle) shape; return new ConstantScoreQuery(makeWithin(bbox)); } else if (shape instanceof Circle) { Circle circle = (Circle) shape; Rectangle bbox = circle.getBoundingBox(); Query approxQuery = makeWithin(bbox); BooleanQuery.Builder bqBuilder = new BooleanQuery.Builder(); FunctionRangeQuery vsRangeQuery = new FunctionRangeQuery( makeDistanceValueSource(circle.getCenter()), 0.0, circle.getRadius(), true, true); bqBuilder.add( approxQuery, BooleanClause.Occur.FILTER); // should have lowest "cost" value; will drive iteration bqBuilder.add(vsRangeQuery, BooleanClause.Occur.FILTER); return new ConstantScoreQuery(bqBuilder.build()); } else { throw new UnsupportedOperationException( "Only Rectangles and Circles are currently supported, " + "found [" + shape.getClass() + "]"); // TODO } }