public override ConstantScoreQuery MakeQuery(SpatialArgs args) { if (!SpatialOperation.Is(args.Operation, SpatialOperation.Intersects, SpatialOperation.IsWithin)) { throw new UnsupportedSpatialOperation(args.Operation); } IShape shape = args.Shape; if (shape is IRectangle) { var bbox = (IRectangle)shape; return(new ConstantScoreQuery(MakeWithin(bbox))); } else if (shape is ICircle) { var circle = (ICircle)shape; var bbox = circle.BoundingBox; var vsf = new ValueSourceFilter( new QueryWrapperFilter(MakeWithin(bbox)), MakeDistanceValueSource(circle.Center), 0, circle.Radius); return(new ConstantScoreQuery(vsf)); } throw new NotSupportedException("Only IRectangles and ICircles are currently supported, " + "found [" + shape.GetType().Name + "]"); //TODO }
public override ConstantScoreQuery MakeQuery(SpatialArgs args) { if (!SpatialOperation.Is(args.Operation, SpatialOperation.Intersects, SpatialOperation.IsWithin)) { throw new UnsupportedSpatialOperation(args.Operation); } Shape shape = args.Shape; var bbox = shape as Rectangle; if (bbox != null) { return(new ConstantScoreQuery(new QueryWrapperFilter(MakeWithin(bbox)))); } var circle = shape as Circle; if (circle != null) { bbox = circle.GetBoundingBox(); var vsf = new ValueSourceFilter( new QueryWrapperFilter(MakeWithin(bbox)), MakeDistanceValueSource(circle.GetCenter()), 0, circle.GetRadius()); return(new ConstantScoreQuery(vsf)); } throw new InvalidOperationException("Only Rectangles and Circles are currently supported, " + "found [" + shape.GetType().Name + "]"); //TODO }
public override Filter MakeFilter(SpatialArgs args) { var op = args.Operation; if (SpatialOperation.Is(op, SpatialOperation.IsWithin, SpatialOperation.Intersects, SpatialOperation.BBoxWithin, SpatialOperation.BBoxIntersects) == false) { throw new UnsupportedSpatialOperation(op); } var shape = args.Shape; var detailLevel = grid.GetLevelForDistance(args.ResolveDistErr(ctx, distErrPct)); return(new RecursivePrefixTreeFilter(GetFieldName(), grid, shape, _prefixGridScanLevel, detailLevel)); }
//TODO this is basically old code that hasn't been verified well and should probably be removed public virtual Query MakeQueryDistanceScore(SpatialArgs args) { // For starters, just limit the bbox var shape = args.Shape; if (!(shape is IRectangle || shape is ICircle)) { throw new NotSupportedException("Only Rectangles and Circles are currently supported, found [" + shape.GetType().Name + "]");//TODO } IRectangle bbox = shape.BoundingBox; if (bbox.CrossesDateLine) { throw new NotSupportedException("Crossing dateline not yet supported"); } ValueSource valueSource = null; Query spatial = null; SpatialOperation op = args.Operation; if (SpatialOperation.Is(op, SpatialOperation.BBoxWithin, SpatialOperation.BBoxIntersects)) { spatial = MakeWithin(bbox); } else if (SpatialOperation.Is(op, SpatialOperation.Intersects, SpatialOperation.IsWithin)) { spatial = MakeWithin(bbox); if (args.Shape is ICircle) { var circle = (ICircle)args.Shape; // Make the ValueSource valueSource = MakeDistanceValueSource(shape.Center); var vsf = new ValueSourceFilter( new QueryWrapperFilter(spatial), valueSource, 0, circle.Radius); spatial = new FilteredQuery(new MatchAllDocsQuery(), vsf); } } else if (op == SpatialOperation.IsDisjointTo) { spatial = MakeDisjoint(bbox); } if (spatial == null) { throw new UnsupportedSpatialOperation(args.Operation); } if (valueSource != null) { valueSource = new CachingDoubleValueSource(valueSource); } else { valueSource = MakeDistanceValueSource(shape.Center); } Query spatialRankingQuery = new FunctionQuery(valueSource); var bq = new BooleanQuery(); bq.Add(spatial, BooleanClause.Occur.MUST); bq.Add(spatialRankingQuery, BooleanClause.Occur.MUST); return(bq); }