/// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override string Execute()
        {
            var indexer = SearchFactory <SearchDocument> .AssetIndexer;

            if (indexer == null)
            {
                return("Indexer not configured");
            }

            OnStatusChanged(string.Format("Starting Crawl at {0:hh mm ss tt}", DateTime.Now));

            try
            {
                var crawler = new AssetCrawler <SearchDocument>(indexer);

                var configData = MissionConfig.GetConfigData();

                var results = crawler.RunCrawler(StatusCallback);

                MissionConfig.SetLastAssetCrawlDate(configData, DateTime.Now, results.Duration);

                return(string.Format("Crawl Finished. {0} assets crawled. {4} Errors. {5} Warnings. Duration ({1:00}:{2:00}:{3:00})", results.TotalCnt, results.Duration.Hours, results.Duration.Minutes, results.Duration.Seconds, results.ErrorCnt, results.WarningCnt));
            }
            catch (Exception ex)
            {
                OnStatusChanged("failed");

                return(string.Format("{0} {1}", ex.Message, ex.StackTrace));
            }
        }
        /// <summary>
        /// Called when a scheduled job executes
        /// </summary>
        /// <returns>A status message to be stored in the database log and visible from admin mode</returns>
        public override string Execute()
        {
            var indexer = SearchFactory <SearchDocument> .ContentIndexer;

            if (indexer == null)
            {
                return("Indexer not configured");
            }

            OnStatusChanged(string.Format("Starting Crawl at {0:hh mm ss tt}", DateTime.Now));

            var configData = MissionConfig.GetConfigData();

            var contentCrawler = new ContentCrawler <SearchDocument>(indexer, new CrawlerSettings()
            {
                PageScrapper  = new PageScrapper(),
                ExcludedPages = TypeParser.ParseCSVIntList(configData.CrawlerPageExclusions),
            });

            var results = contentCrawler.RunCrawler(StatusCallback, configData.LastContentCrawledDate);

            MissionConfig.SetLastContentCrawlDate(configData, DateTime.Now, results.Duration);

            OnStatusChanged("Done");

            return(string.Format("Crawl Finished. {0} pages crawled. Total Errors {4}. Duration ({1:00}:{2:00}:{3:00}) ", results.TotalCnt, results.Duration.Hours, results.Duration.Minutes, results.Duration.Seconds, results.ErrorCnt));
        }
        public ActionResult Index()
        {
            var viewModel = new SearchAdminViewModel();

            var configData = MissionConfig.GetConfigData();

            if (configData.LastContentCrawledDate != null)
            {
                viewModel.LastContentCrawlDate = configData.LastContentCrawledDate.Value.ToString("MM-dd-yyyy hh:mm:ss");
            }

            if (configData.LastAssetCrawledDate != null)
            {
                viewModel.LastAssetCrawlDate = configData.LastAssetCrawledDate.Value.ToString("MM-dd-yyyy hh:mm:ss");
            }

            viewModel.IndexOnPublishContent = configData.IndexOnPublishContent;
            viewModel.IndexOnPublishAsset   = configData.IndexOnPublishAsset;
            viewModel.CrawlerPageExclusions = configData.CrawlerPageExclusions;

            viewModel.Status = "Online";

            try
            {
                var srchClient = SearchFactory <SearchDocument> .SearchClient;
                viewModel.SearchServer = srchClient.SrchConnStr;
                viewModel.SearchClient = srchClient.GetType().Name;

                var req = new SearchRequest()
                {
                    QueryText = "*:*"
                };

                req.Facets.Add(new FieldFacet("mimetype", ""));

                var result = srchClient.Search(req);

                viewModel.IndexTotalItems = result.TotalFound;

                if (result.Refinements.Any())
                {
                    viewModel.IndexCounts = result.Refinements[0].Items.ToDictionary(t => t.DisplayName, t => t.Count);
                }
            }
            catch
            {
                viewModel.Status = "Offline";
            }

            return(View("~/modules/MissionSearchEpi/UI/Views/SearchAdmin/index.cshtml", viewModel));
        }
        public ActionResult SaveSettings()
        {
            var indexContent = Request["IndexOnPublishContent"];
            var indexAsset   = Request["IndexOnPublishAsset"];

            var configData = MissionConfig.GetConfigData();

            configData.IndexOnPublishContent = (indexContent.Contains("true"));
            configData.IndexOnPublishAsset   = (indexAsset.Contains("true"));
            configData.CrawlerPageExclusions = Request["CrawlerPageExclusions"];

            MissionConfig.SaveConfigData(configData);

            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        private void DeleteFromIndex(ContentEventArgs e)
        {
            var configData = MissionConfig.GetConfigData();

            if (e.Content is ISearchableAsset && configData.IndexOnPublishAsset)
            {
                var content = e.Content as ISearchableAsset;

                var indexer = SearchFactory <SearchDocument> .AssetIndexer;
                indexer.Delete(content);
            }
            else if (e.Content is ISearchableContent && configData.IndexOnPublishContent)
            {
                var pageData = e.Content as PageData;
                var id       = string.Format("{0}-{1}", pageData.ContentGuid, pageData.Language);
                SearchFactory <SearchDocument> .SearchClient.DeleteById(id);
            }
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        private void PublishToIndex(ContentEventArgs e)
        {
            var configData = MissionConfig.GetConfigData();

            if (configData.IndexOnPublishContent && e.Content.GetType().IsSubclassOf(typeof(BlockData)))
            {
                var repository = ServiceLocator.Current.GetInstance <IContentRepository>();

                var pages = repository.GetReferencesToContent(e.Content.ContentLink, false);

                if (pages == null)
                {
                    return;
                }

                var contentCrawler = new ContentCrawler <SearchDocument>(new CrawlerSettings());

                foreach (var pageRef in pages)
                {
                    var page = repository.Get <IContent>(pageRef.OwnerID);

                    if (page != null)
                    {
                        var pageData = page as PageData;

                        if (pageData != null)
                        {
                            var searchableContent = contentCrawler.BuildSearchablePage(pageData);

                            if (searchableContent != null)
                            {
                                SearchFactory <SearchDocument> .ContentIndexer.Update(searchableContent);
                            }
                        }
                    }
                }
            }
            else if (configData.IndexOnPublishAsset && e.Content is ISearchableAsset)
            {
                var mediaData = e.Content as MediaData;

                var crawler = new AssetCrawler <SearchDocument>();

                var searchableContent = crawler.BuildSearchableAsset(mediaData);

                if (searchableContent != null)
                {
                    SearchFactory <SearchDocument> .AssetIndexer.Update(searchableContent);
                }
            }
            else if (configData.IndexOnPublishContent && e.Content is ISearchableContent)
            {
                var pageData = e.Content as PageData;

                var contentCrawler = new ContentCrawler <SearchDocument>(new CrawlerSettings());

                var searchableContent = contentCrawler.BuildSearchablePage(pageData);

                if (searchableContent == null)
                {
                    return;
                }

                // if moving item then use target link instead of parent link
                if (e.TargetLink != null && e.TargetLink.ID != 0)
                {
                    var pageCrawlMetadata = searchableContent as ContentCrawlProxy;

                    if (pageCrawlMetadata != null)
                    {
                        pageCrawlMetadata.Content.Add(new CrawlerContent()
                        {
                            Name  = "parent",
                            Value = EpiHelper.GetParentName(e.TargetLink.ToPageReference()),
                        });

                        pageCrawlMetadata.Content.Add(new CrawlerContent()
                        {
                            Name  = "path",
                            Value = EpiHelper.GetPageTreePath(e.TargetLink.ToPageReference()),
                        });

                        pageCrawlMetadata.Content.Add(new CrawlerContent()
                        {
                            Name  = "paths",
                            Value = EpiHelper.GetPageTreePaths(e.TargetLink.ToPageReference()),
                        });

                        pageCrawlMetadata.Content.Add(new CrawlerContent()
                        {
                            Name  = "folder",
                            Value = EpiHelper.GetParentName(e.TargetLink.ToPageReference()),
                        });
                    }
                }

                SearchFactory <SearchDocument> .ContentIndexer.Update(searchableContent);
            }
        }