예제 #1
0
        protected virtual Lucene.Net.Search.Query VisitWithinBounds(WithinBoundsNode node, LuceneQueryMapperState mappingState)
        {
            SpatialContext ctx = SpatialContext.GEO;

            var strategy = new PointVectorStrategy(ctx, Sitecore.ContentSearch.Spatial.Common.Constants.LocationFieldName);

            if (node.MinLatitude is double && node.MinLongitude is double && node.MaxLatitude is double && node.MaxLongitude is double)
            {
                //var distance = DistanceUtils.Dist2Degrees((double)node.Radius, DistanceUtils.EARTH_MEAN_RADIUS_KM);
                var rectangle = ctx.MakeRectangle((double)node.MinLongitude, (double)node.MaxLongitude, (double)node.MinLatitude, (double)node.MaxLatitude);

                var spatialArgs = new SpatialArgs(SpatialOperation.IsWithin, rectangle);
                var filter      = strategy.MakeFilter(spatialArgs);


                var dq = strategy.MakeQuery(spatialArgs);

                //DistanceReverseValueSource valueSource = new DistanceReverseValueSource(strategy, rectangle.GetCenter(), double.MaxValue);
                //ValueSourceFilter vsf = new ValueSourceFilter(new QueryWrapperFilter(dq), valueSource, 0, double.MaxValue);
                var filteredSpatial = new FilteredQuery(new MatchAllDocsQuery(), filter);
                //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");
        }
 protected virtual Sitecore.ContentSearch.Linq.Nodes.QueryNode VisitWithinBounds(WithinBoundsNode node, LuceneQueryOptimizerState mappingState)
 {
     return(new WithinBoundsNode(node.Field, node.MinLatitude, node.MinLongitude, node.MaxLatitude, node.MaxLongitude, mappingState.Boost));
 }