コード例 #1
0
        public void AddPoint(int id, string name, double lat, double lng, IndexWriter currentWriter)
        {
            EnsureDistanceMatrixReady();
            var      writer = currentWriter != null ? currentWriter : MakeWriter(true, IndexWriter.MaxFieldLength.UNLIMITED);
            Document doc    = new Document();

            doc.Add(new Field("name", name, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("PostID", Convert.ToString(id), Field.Store.YES, Field.Index.UN_TOKENIZED));

            // convert the lat / long to lucene fields
            doc.Add(new Field(LatField, NumericUtils.DoubleToPrefixCoded(lat), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(LngField, NumericUtils.DoubleToPrefixCoded(lng), Field.Store.YES, Field.Index.NOT_ANALYZED));

            // add a default meta field to make searching all documents easy
            doc.Add(new Field("metafile", "doc", Field.Store.YES, Field.Index.ANALYZED));

            int ctpsize = _ctps.Count;

            for (int i = 0; i < ctpsize; i++)
            {
                CartesianTierPlotter ctp = _ctps[i];
                var boxId = ctp.GetTierBoxId(lat, lng);
                doc.Add(new Field(ctp.GetTierFieldName(),
                                  NumericUtils.DoubleToPrefixCoded(boxId),
                                  Field.Store.YES,
                                  Field.Index.NOT_ANALYZED_NO_NORMS));
            }
            writer.AddDocument(doc);

            if (currentWriter == null)             // if we're not using the passed along writer, which is supposed to be terminated by the caller, then end our new writer
            {
                FinishWriter(writer);
            }
        }
コード例 #2
0
        private void AddPoint(IndexWriter writer, String name, double lat, double lng)
        {
            Document doc = new Document();

            doc.Add(new Field("name", name, Field.Store.YES, Field.Index.ANALYZED));

            // convert the lat / long to lucene fields
            doc.Add(new Field(LatField, NumericUtils.DoubleToPrefixCoded(lat), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(LngField, NumericUtils.DoubleToPrefixCoded(lng), Field.Store.YES, Field.Index.NOT_ANALYZED));

            // add a default meta field to make searching all documents easy
            doc.Add(new Field("metafile", "doc", Field.Store.YES, Field.Index.ANALYZED));

            int ctpsize = _ctps.Count;

            for (int i = 0; i < ctpsize; i++)
            {
                CartesianTierPlotter ctp = _ctps[i];
                var boxId = ctp.GetTierBoxId(lat, lng);
                doc.Add(new Field(ctp.GetTierFieldName(),
                                  NumericUtils.DoubleToPrefixCoded(boxId),
                                  Field.Store.YES,
                                  Field.Index.NOT_ANALYZED_NO_NORMS));
            }
            writer.AddDocument(doc);
        }
コード例 #3
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;
                    }
                }
            }
        }
コード例 #4
0
ファイル: LookService.cs プロジェクト: greystate/umbraco-look
        /// <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;
            }
        }
コード例 #5
0
        public void Set(string name, object value, Document document, Field.Store store, Field.Index index, float?boost)
        {
            var service  = (Service)value;
            var location = service.Location;
            var lat      = new Field("Location_Latitude", NumericUtils.DoubleToPrefixCoded(location.Y), Field.Store.YES, Field.Index.NOT_ANALYZED);
            var lng      = new Field("Location_Longitude", NumericUtils.DoubleToPrefixCoded(location.X), Field.Store.YES, Field.Index.NOT_ANALYZED);

            document.Add(lat);
            document.Add(lng);

            document.Add(new Field("metafile", "doc", Field.Store.YES, Field.Index.ANALYZED));

            int ctpsize = Ctps.Count;

            for (int i = 0; i < ctpsize; i++)
            {
                CartesianTierPlotter ctp = Ctps[i];
                var boxId = ctp.GetTierBoxId(location.Y, location.X);
                document.Add(new Field(ctp.GetTierFieldName(), NumericUtils.DoubleToPrefixCoded(boxId), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
            }
        }
コード例 #6
0
        public Shape GetShapeLoop(Shape shape, CartesianTierPlotter ctp, double latX, double longX, double latY, double longY)
        {
            double beginAt = ctp.GetTierBoxId(latX, longX);
            double endAt   = ctp.GetTierBoxId(latY, longY);

            double tierVert = ctp.TierVerticalPosDivider;

            double startX = beginAt - (beginAt % 1);
            double startY = beginAt - startX;             //should give a whole number

            double endX = endAt - (endAt % 1);
            double endY = endAt - endX;             //should give a whole number

            int scale = (int)Math.Log10(tierVert);

            endY   = Math.Round(endY, scale, MidpointRounding.ToEven);
            startY = Math.Round(startY, scale, MidpointRounding.ToEven);

            double xInc = 1.0d / tierVert;

            xInc = Math.Round(xInc, scale, MidpointRounding.ToEven);

            for (; startX <= endX; startX++)
            {
                double itY = startY;

                while (itY <= endY)
                {
                    //create a boxId
                    // startX.startY
                    double boxId = startX + itY;
                    shape.AddBox(boxId);

                    itY += Math.Round(xInc, scale, MidpointRounding.ToEven);
                }
            }
            return(shape);
        }
コード例 #7
0
        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);
        }