@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
   }
 }
예제 #2
0
 @Test
 public void testRectangle() throws IOException {
   Shape s = read("-10 -20 10 20");
   assertEquals(ctx.makeRectangle(-10, 10, -20, 20), s);
   assertEquals(s, writeThenRead(s));
   assertTrue(s.hasArea());
 }
예제 #3
0
 @Test
 public void testCircle() throws IOException {
   Shape s = read("Circle(1.23 4.56 distance=7.89)");
   assertEquals(ctx.makeCircle(1.23, 4.56, 7.89), s);
   assertEquals(s, writeThenRead(s));
   assertEquals(s, read("CIRCLE( 4.56,1.23 d=7.89 )")); // use lat,lon and use 'd' abbreviation
   assertTrue(s.hasArea());
 }
예제 #4
0
 @Test
 public void testPoint() throws IOException {
   Shape s = read("10 20");
   assertEquals(ctx.makePoint(10, 20), s);
   assertEquals(s, writeThenRead(s));
   assertEquals(s, read("20,10")); // check comma for y,x format
   assertEquals(s, read("20, 10")); // test space
   assertFalse(s.hasArea());
 }