示例#1
0
        /// <summary>
        /// Initialize the look service - it caches reference to all lucene folders and sets up CartesianTierPlotters
        /// </summary>
        internal static void Initialize(UmbracoHelper umbracoHelper)
        {
            if (!LookService.Instance._initialized)
            {
                lock (LookService.Instance._initializationLock)
                {
                    if (!LookService.Instance._initialized)
                    {
                        LogHelper.Info(typeof(LookService), "Initializing...");

                        LookService.Instance._umbracoHelper = umbracoHelper;

                        IndexProviderCollection indexProviderCollection = null;

                        try
                        {
                            indexProviderCollection = ExamineManager.Instance.IndexProviderCollection;
                        }
                        catch
                        {
                            // running outside of Umbraco - in unit test context
                        }

                        if (indexProviderCollection != null)
                        {
                            var indexProviders = indexProviderCollection
                                                 .Select(x => x as LuceneIndexer)
                                                 .Where(x => x != null)
                                                 .ToArray();

                            // cache the collection of Lucene Directory objs (so don't have to at query time)
                            LookService.Instance._indexSetDirectories = indexProviders.ToDictionary(x => x.IndexSetName, x => x.GetLuceneDirectory());
                        }

                        // init collection of cartesian tier plotters
                        IProjector projector = new SinusoidalProjector();
                        var        plotter   = new CartesianTierPlotter(0, projector, LookConstants.LocationTierFieldPrefix);

                        var startTier = plotter.BestFit(LookService._maxDistance);
                        var endTier   = plotter.BestFit(1); // min of a 1 mile search

                        for (var tier = startTier; tier <= endTier; tier++)
                        {
                            LookService
                            .Instance
                            ._cartesianTierPlotters
                            .Add(new CartesianTierPlotter(
                                     tier,
                                     projector,
                                     LookConstants.LocationTierFieldPrefix));
                        }

                        LookService.Instance._initialized = true;
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Wire up the indexing event if both the configured indexer & searcher found
        /// </summary>
        /// <param name="action">indexing event</param>
        /// <param name="umbracoHelper"></param>
        internal static void Initialize(Action <object, IndexingNodeDataEventArgs, UmbracoHelper> action, UmbracoHelper umbracoHelper)
        {
            LogHelper.Info(typeof(LookService), "Initializing");

            var valid = true;

            if (LookService.Indexer == null)
            {
                LogHelper.Warn(typeof(LookService), $"Examine Indexer '{LookService.Instance.IndexerName}' Not Found");

                valid = false;
            }
            else if (!(LookService.Indexer is LuceneIndexer))
            {
                // should this ever happen ?

                LogHelper.Warn(typeof(LookService), "Examine Indexer is not of type LuceneIndexer");

                valid = false;
            }

            if (LookService.Searcher == null)
            {
                LogHelper.Warn(typeof(LookService), $"Examine Searcher '{LookService.Instance.SearcherName}' Not Found");

                valid = false;
            }

            if (!valid)
            {
                LogHelper.Warn(typeof(LookService), "Error initializing LookService");
            }
            else
            {
                LogHelper.Info(typeof(LookService), "Indexer & Searcher valid for the LookService");

                // init collection of cartesian tier plotters (and store in singleton)
                IProjector projector = new SinusoidalProjector();
                var        plotter   = new CartesianTierPlotter(0, projector, CartesianTierPlotter.DefaltFieldPrefix);

                var startTier = plotter.BestFit(LookService.MaxDistance);
                var endTier   = plotter.BestFit(1); // min of a 1 mile search

                for (var tier = startTier; tier <= endTier; tier++)
                {
                    LookService.Instance.CartesianTierPlotters.Add(
                        new CartesianTierPlotter(tier, projector, CartesianTierPlotter.DefaltFieldPrefix));
                }

                // wire-up events
                LookService.Indexer.GatheringNodeData += (sender, e) => action(sender, e, umbracoHelper);

                ((LuceneIndexer)LookService.Indexer).DocumentWriting += LookIndexService.DocumentWriting;
            }
        }
        public Shape GetBoxShape(double latitude, double longitude, double miles)
        {
            if (miles < MilesFloor)
            {
                miles = MilesFloor;
            }
            //Rectangle box = DistanceUtils.GetInstance().GetBoundary(latitude, longitude, miles);
            LLRect box1 = LLRect.CreateBox(new FloatLatLng(latitude, longitude), miles, miles);
            LatLng ll   = box1.GetLowerLeft();
            LatLng ur   = box1.GetUpperRight();

            double latY   = ur.GetLat();
            double latX   = ll.GetLat();
            double longY  = ur.GetLng();
            double longX  = ll.GetLng();
            double longX2 = 0.0;

            if (ur.GetLng() < 0.0 && ll.GetLng() > 0.0)
            {
                longX2 = ll.GetLng();
                longX  = -180.0;
            }
            if (ur.GetLng() > 0.0 && ll.GetLng() < 0.0)
            {
                longX2 = ll.GetLng();
                longX  = 0.0;
            }

            var ctp     = new CartesianTierPlotter(2, _projector, _tierPrefix);
            int bestFit = ctp.BestFit(miles);

            ctp = new CartesianTierPlotter(bestFit, _projector, _tierPrefix);

            var shape = new Shape(ctp.GetTierFieldName());

            // generate shape
            // iterate from startX->endX
            // iterate from startY -> endY
            // shape.add(currentLat.currentLong);

            shape = GetShapeLoop(shape, ctp, latX, longX, latY, longY);
            if (longX2 != 0.0)
            {
                if (longX2 != 0.0)
                {
                    if (longX == 0.0)
                    {
                        longX = longX2;
                        longY = 0.0;
                        shape = GetShapeLoop(shape, ctp, latX, longX, latY, longY);
                    }
                    else
                    {
                        longX = longX2;
                        longY = -180.0;
                        shape = GetShapeLoop(shape, ctp, latY, longY, latX, longX);
                    }
                }
            }

            return(shape);
        }