Beispiel #1
0
        /// <summary>
        /// Requests a registered object to unregister on app domain unload in a web project
        /// </summary>
        /// <param name="immediate">true to indicate the registered object should unregister from the hosting environment before returning; otherwise, false.</param>
        public void Stop(bool immediate)
        {
            if (immediate)
            {
                //This is sort of a hack at the moment. We are disposing the searchers at the last possible point in time because there might
                // still be pages executing when 'immediate' == false. In which case, when we close the readers, exceptions will occur
                // if the search results are still being enumerated.
                // I've tried using DecRef and IncRef to keep track of searchers using readers, however there is no guarantee that DecRef can
                // be called when a search is finished and since search results are lazy, we don't know when they end unless people dispose them
                // or always use a foreach loop which can't really be forced. The only alternative to using DecRef and IncRef would be to make the results
                // not lazy which isn't good.

                foreach (var searcher in SearchProviderCollection.OfType <IDisposable>())
                {
                    searcher.Dispose();
                }

                OpenReaderTracker.Current.CloseAllReaders();

                HostingEnvironment.UnregisterObject(this);
            }
            else
            {
                foreach (var indexer in IndexProviderCollection.OfType <IDisposable>())
                {
                    indexer.Dispose();
                }
            }
        }
Beispiel #2
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;
                    }
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Requests a registered object to unregister on app domain unload in a web project
 /// </summary>
 /// <param name="immediate">true to indicate the registered object should unregister from the hosting environment before returning; otherwise, false.</param>
 public void Stop(bool immediate)
 {
     foreach (var searcher in SearchProviderCollection.OfType <IDisposable>())
     {
         searcher.Dispose();
     }
     foreach (var indexer in IndexProviderCollection.OfType <IDisposable>())
     {
         indexer.Dispose();
     }
 }
Beispiel #4
0
        /// <summary>
        /// Before any of the index/search collections are accessed, the providers need to be loaded
        /// </summary>
        private void EnsureProviders()
        {
            if (!_providersInit)
            {
                lock (_lock)
                {
                    // Do this again to make sure _provider is still null
                    if (!_providersInit)
                    {
                        // Load registered providers and point _provider to the default provider

                        _indexProviderCollection = new IndexProviderCollection();
                        ProvidersHelper.InstantiateProviders(ExamineSettings.Instance.IndexProviders.Providers, _indexProviderCollection, typeof(BaseIndexProvider));

                        _searchProviderCollection = new SearchProviderCollection();
                        ProvidersHelper.InstantiateProviders(ExamineSettings.Instance.SearchProviders.Providers, _searchProviderCollection, typeof(BaseSearchProvider));

                        //set the default
                        if (!string.IsNullOrEmpty(ExamineSettings.Instance.SearchProviders.DefaultProvider))
                        {
                            _defaultSearchProvider = _searchProviderCollection[ExamineSettings.Instance.SearchProviders.DefaultProvider];
                        }

                        if (_defaultSearchProvider == null)
                        {
                            throw new ProviderException("Unable to load default search provider");
                        }

                        _providersInit = true;


                        //check if we need to rebuild on startup
                        if (ExamineSettings.Instance.RebuildOnAppStart)
                        {
                            foreach (var index in _indexProviderCollection.Cast <IIndexer>())
                            {
                                if (!index.IndexExists())
                                {
                                    var args = new BuildingEmptyIndexOnStartupEventArgs(index);
                                    OnBuildingEmptyIndexOnStartup(args);
                                    if (!args.Cancel)
                                    {
                                        index.RebuildIndex();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Before any of the index/search collections are accessed, the providers need to be loaded
        /// </summary>
        private void EnsureProviders()
        {
            if (!_providersInit)
            {
                lock (_lock)
                {
                    // Do this again to make sure _provider is still null
                    if (!_providersInit)
                    {
                        // Load registered providers and point _provider to the default provider	

                        _indexProviderCollection = new IndexProviderCollection();
                        ProvidersHelper.InstantiateProviders(ExamineSettings.Instance.IndexProviders.Providers, _indexProviderCollection, typeof(BaseIndexProvider));

                        _searchProviderCollection = new SearchProviderCollection();
                        ProvidersHelper.InstantiateProviders(ExamineSettings.Instance.SearchProviders.Providers, _searchProviderCollection, typeof(BaseSearchProvider));

                        //set the default
                        if (!string.IsNullOrEmpty(ExamineSettings.Instance.SearchProviders.DefaultProvider))
                            _defaultSearchProvider = _searchProviderCollection[ExamineSettings.Instance.SearchProviders.DefaultProvider];

                        if (_defaultSearchProvider == null)
                            throw new ProviderException("Unable to load default search provider");

                        _providersInit = true;


                        //check if we need to rebuild on startup
                        if (ExamineSettings.Instance.RebuildOnAppStart)
                        {
                            foreach (var index in _indexProviderCollection.Cast<IIndexer>())
                            {
                                if (!index.IndexExists())
                                {
                                    var args = new BuildingEmptyIndexOnStartupEventArgs(index);
                                    OnBuildingEmptyIndexOnStartup(args);
                                    if (!args.Cancel)
                                    {
                                        index.RebuildIndex();    
                                    }
                                }
                            }    
                        }

                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Before any of the index/search collections are accessed, the providers need to be loaded
        /// </summary>
        private void EnsureProviders()
        {
            if (!_providersInit)
            {
                lock (_lock)
                {
                    // Do this again to make sure _provider is still null
                    if (!_providersInit)
                    {
                        // Load registered providers and point _provider to the default provider

                        _indexProviderCollection = new IndexProviderCollection();
                        ProvidersHelper.InstantiateProviders(ExamineSettings.Instance.IndexProviders.Providers, _indexProviderCollection, typeof(BaseIndexProvider));

                        _searchProviderCollection = new SearchProviderCollection();
                        ProvidersHelper.InstantiateProviders(ExamineSettings.Instance.SearchProviders.Providers, _searchProviderCollection, typeof(BaseSearchProvider));

                        //set the default
                        if (!string.IsNullOrEmpty(ExamineSettings.Instance.SearchProviders.DefaultProvider))
                        {
                            _defaultSearchProvider = _searchProviderCollection[ExamineSettings.Instance.SearchProviders.DefaultProvider];
                        }

                        if (_defaultSearchProvider == null)
                        {
                            throw new ProviderException("Unable to load default search provider");
                        }

                        _providersInit = true;


                        //check if we need to rebuild on startup
                        if (ExamineSettings.Instance.RebuildOnAppStart)
                        {
                            foreach (IIndexer index in _indexProviderCollection)
                            {
                                var       rebuild     = false;
                                var       healthy     = true;
                                Exception unhealthyEx = null;
                                var       exists      = index.IndexExists();
                                if (!exists)
                                {
                                    rebuild = true;
                                }
                                if (!rebuild)
                                {
                                    healthy = IsIndexHealthy(index, out unhealthyEx);
                                    if (!healthy)
                                    {
                                        rebuild = true;
                                    }
                                }
                                //if it doesn't exist ... or if it's unhealthy/corrupt

                                if (rebuild)
                                {
                                    var args = new BuildingEmptyIndexOnStartupEventArgs(index, healthy, unhealthyEx);
                                    OnBuildingEmptyIndexOnStartup(args);
                                    if (!args.Cancel)
                                    {
                                        index.RebuildIndex();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }