/// <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); } }
/// <summary> /// Used to intialize default properties /// </summary> /// <param name="page"></param> /// <returns></returns> public ContentCrawlProxy BuildSearchablePage(PageData page) { var searchablePage = page as ISearchableContent; if (searchablePage == null) { return(null); } searchablePage._ContentID = string.Format("{0}-{1}", page.ContentGuid, page.Language.Name); var pageProps = new ContentCrawlProxy(); pageProps.Content.Add(new CrawlerContent() { Name = "title", Value = page.Name, }); pageProps.Content.Add(new CrawlerContent() { Name = "timestamp", Value = page.Changed, }); pageProps.Content.Add(new CrawlerContent() { Name = "url", Value = page.LinkURL.Replace("epslanguage=en", string.Format("epslanguage={0}", page.Language.Name)), }); pageProps.Content.Add(new CrawlerContent() { Name = "contentid", Value = page.ContentLink.ID.ToString(), }); pageProps.Content.Add(new CrawlerContent() { Name = "categories", Value = EpiHelper.GetCategoryPaths(page.Category), }); pageProps.Content.Add(new CrawlerContent() { Name = "hostname", Value = EpiHelper.GetSitePath(page.ContentLink), }); pageProps.Content.Add(new CrawlerContent() { Name = "folder", Value = EpiHelper.GetParentName(page.ParentLink.ToPageReference()), }); pageProps.Content.Add(new CrawlerContent() { Name = "path", Value = EpiHelper.GetPageTreePath(page.ParentLink.ToPageReference()), }); pageProps.Content.Add(new CrawlerContent() { Name = "paths", Value = EpiHelper.GetPageTreePaths(page.ParentLink.ToPageReference()), }); pageProps.Content.Add(new CrawlerContent() { Name = "pagetype", Value = page.PageTypeName, }); pageProps.Content.Add(new CrawlerContent() { Name = "mimetype", Value = "text/html", }); pageProps.Content.Add(new CrawlerContent() { Name = "contenttype", Value = "HTML", }); pageProps.Content.Add(new CrawlerContent() { Name = "language", Value = new List <string>() { page.Language.Name, }, }); // if enabled scrape page content if (_crawlSettings.PageScrapper != null) { var scrapContent = _crawlSettings.PageScrapper.ScrapPage(EpiHelper.GetExternalURL(page)); pageProps.Content.Add(new CrawlerContent() { Name = MissionSearch.Global.ContentField, Value = scrapContent, }); } // parse searchable block data and add to content var parsedBlockText = ProcessContentReferences(page); if (parsedBlockText.Any()) { pageProps.Content.AddRange(parsedBlockText); } //searchablePage.CrawlProperties = pageCrawlMetadata; pageProps.ContentItem = searchablePage; return(pageProps); }