Simple {@link SpatialStrategy} which represents Points in two numeric {@link DoubleField}s. Note, currently only Points can be indexed by this Strategy. At query time, the bounding box of the given Shape is used to create {@link NumericRangeQuery}s to efficiently find Points within the Shape. Due to the simple use of numeric fields, this Strategy provides support for sorting by distance through {@link DistanceValueSource}
Inheritance: SpatialStrategy
Esempio n. 1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <exception cref="ArgumentNullException"><paramref name="strategy"/> or <paramref name="from"/> is <c>null</c>.</exception>
 public DistanceValueSource(PointVectorStrategy strategy, IPoint from, double multiplier)
 {
     // LUCENENET specific - added guard clauses
     this.strategy   = strategy ?? throw new ArgumentNullException(nameof(strategy));
     this.from       = from ?? throw new ArgumentNullException(nameof(from));
     this.multiplier = multiplier;
 }
 public DistanceReverseValueSource(PointVectorStrategy strategy, Point from, double max)
     : base(strategy, from)
 {
     this.strategy = strategy;
     this.from = from;
     this.max = max;
 }
        private List<IFieldable> AddPoint(Item item)
        {
            List<IFieldable> pointFields = new List<IFieldable>();
            var setting = spatialConfigurations.LocationSettings.Where(i => i.TemplateId.Equals(item.TemplateID)).FirstOrDefault();
            if (setting == null)
                return pointFields;

            SpatialContext ctx =  SpatialContext.GEO;
             
            SpatialPrefixTree grid = new GeohashPrefixTree(ctx, 11);
            var strategy = new PointVectorStrategy(ctx, Sitecore.ContentSearch.Spatial.Common.Constants.LocationFieldName);
            
            double lng = 0;
            double lat = 0;
            bool parsedLat = false;
            bool parsedLong = false;

            if (!string.IsNullOrEmpty(item[setting.LatitudeField]))
            {
                parsedLat = Double.TryParse(item[setting.LatitudeField], out lat);
            }

            if (!string.IsNullOrEmpty(item[setting.LongitudeField]))
            {
                parsedLong = Double.TryParse(item[setting.LongitudeField], out lng);
            }
            if (!parsedLat && !parsedLong)
                return pointFields;

            pointFields = AddPoint( lng, lat);
            
            return pointFields;
        }
        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");
        }
Esempio n. 5
0
            public IEnumerable<Param> ParamsProvider()
            {
                var ctorArgs = new List<Param>();

                SpatialContext ctx = SpatialContext.GEO;

                SpatialPrefixTree grid = new GeohashPrefixTree(ctx, 12);
                SpatialStrategy strategy = new RecursivePrefixTreeStrategy(grid, "recursive_geohash");
                ctorArgs.Add(new Param(strategy));

                grid = new QuadPrefixTree(ctx, 25);
                strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad");
                ctorArgs.Add(new Param(strategy));

                grid = new GeohashPrefixTree(ctx, 12);
                strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash");
                ctorArgs.Add(new Param(strategy));

                strategy = new PointVectorStrategy(ctx, "pointvector");
                ctorArgs.Add(new Param(strategy));

                return ctorArgs;
            }
Esempio n. 6
0
        //@ParametersFactory
        public static IList<Object[]> Parameters()
        {
            List<Object[]> ctorArgs = new List<object[]>();

            SpatialContext ctx = SpatialContext.GEO;
            SpatialPrefixTree grid;
            SpatialStrategy strategy;

            grid = new QuadPrefixTree(ctx, 25);
            strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad");
            ctorArgs.Add(new Object[] { new Param(strategy) });

            grid = new GeohashPrefixTree(ctx, 12);
            strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash");
            ctorArgs.Add(new Object[] { new Param(strategy) });

            strategy = new PointVectorStrategy(ctx, "pointvector");
            ctorArgs.Add(new Object[] { new Param(strategy) });

            strategy = new SerializedDVStrategy(ctx, "serialized");
            ctorArgs.Add(new Object[] { new Param(strategy) });

            return ctorArgs;
        }
Esempio n. 7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public DistanceValueSource(PointVectorStrategy strategy, IPoint from, double multiplier)
 {
     this.strategy   = strategy;
     this.from       = from;
     this.multiplier = multiplier;
 }
Esempio n. 8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public DistanceValueSource(PointVectorStrategy strategy, IPoint from, double multiplier)
 {
     this.strategy = strategy;
     this.from = from;
     this.multiplier = multiplier;
 }
Esempio n. 9
0
 public DistanceValueSource(PointVectorStrategy strategy, Point from)
 {
     this.strategy = strategy;
     this.from = from;
 }
Esempio n. 10
0
 public DistanceValueSource(PointVectorStrategy strategy, Point from)
 {
     this.strategy = strategy;
     this.from     = from;
 }
 private static List<IFieldable> AddPoint(double lng, double lat)
 {
     SpatialContext ctx =  SpatialContext.GEO;
      
     var strategy = new PointVectorStrategy(ctx, Sitecore.ContentSearch.Spatial.Common.Constants.LocationFieldName);//var strategy = new PrefixTreeStrategy(ctx, Sitecore.ContentSearch.Spatial.Common.Constants.LocationFieldName);
      
     List<IFieldable> pointFields = new List<IFieldable>();
     Point shape = ctx.MakePoint(lng, lat);
     foreach (var f in strategy.CreateIndexableFields(shape))
     {
         if (f != null)
         {
             pointFields.Add(f);
         }
     }
     return pointFields;
 }