min
max
protected virtual Lucene.Net.Search.Query VisitWithinRadius(WithinRadiusNode node, LuceneQueryMapperState mappingState) { SpatialContext ctx = SpatialContext.GEO; var strategy = new PointVectorStrategy(ctx, Sitecore.ContentSearch.Spatial.Common.Constants.LocationFieldName); if (node.Latitude is double && node.Longitude is double && node.Radius is double) { var distance = DistanceUtils.Dist2Degrees((double)node.Radius, DistanceUtils.EARTH_MEAN_RADIUS_MI); Circle circle = ctx.MakeCircle((double)node.Longitude,(double)node.Latitude, distance); var spatialArgs = new SpatialArgs(SpatialOperation.IsWithin, circle); var dq = strategy.MakeQuery(spatialArgs); DistanceReverseValueSource valueSource = new DistanceReverseValueSource(strategy, circle.GetCenter(), distance); ValueSourceFilter vsf = new ValueSourceFilter(new QueryWrapperFilter(dq), valueSource, 0, distance); var filteredSpatial = new FilteredQuery(new MatchAllDocsQuery(), vsf); mappingState.FilterQuery = filteredSpatial; Lucene.Net.Search.Query spatialRankingQuery = new FunctionQuery(valueSource); Random r = new Random(DateTime.Now.Millisecond); var randomNumber = r.Next(10000101,11000101); Lucene.Net.Search.Query dummyQuery = Lucene.Net.Search.NumericRangeQuery.NewIntRange("__smallcreateddate", randomNumber, Int32.Parse(DateTime.Now.ToString("yyyyMMdd")), true, true); BooleanQuery bq = new BooleanQuery(); bq.Add(filteredSpatial, Occur.MUST); bq.Add(spatialRankingQuery, Occur.MUST); bq.Add(dummyQuery, Occur.SHOULD); return bq; } throw new NotSupportedException("Wrong parameters type, Radius, latitude and longitude must be of type double"); }
public ValueSourceFilteredDocIdSet(DocIdSet innerSet, FunctionValues values, ValueSourceFilter caller) : base(innerSet) { this.enclosingFilter = caller; this.values = values; }
public override Query MakeQuery(SpatialArgs args) { // For starters, just limit the bbox var shape = args.GetShape(); if (!(shape is Rectangle || shape is Circle)) throw new InvalidShapeException("Only Rectangles and Circles are currently supported, found [" + shape.GetType().Name + "]");//TODO Rectangle bbox = shape.GetBoundingBox(); if (bbox.GetCrossesDateLine()) { throw new InvalidOperationException("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); var circle = args.GetShape() as Circle; if (circle != null) { // Make the ValueSource valueSource = MakeValueSource(args); var vsf = new ValueSourceFilter( new QueryWrapperFilter(spatial), valueSource, 0, circle.GetRadius()); 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 = MakeValueSource(args); } Query spatialRankingQuery = new FunctionQuery(valueSource); var bq = new BooleanQuery(); bq.Add(spatial, Occur.MUST); bq.Add(spatialRankingQuery, Occur.MUST); return bq; }
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 ValueSourceFilteredDocIdSet(ValueSourceFilter outerInstance, DocIdSet innerSet, FunctionValues values) : base(innerSet) { this.outerInstance = outerInstance; this.values = values; }