protected string FormatLinkText(IndexItem indexItem) { if (indexItem.Title.Length > 0) { return indexItem.PageName + " > " + indexItem.Title; } return indexItem.PageName; }
public string FormatCreatedDate(IndexItem indexItem) { if ((!displaySettings.ShowCreatedDate) || (timeZone == null)) { return string.Empty; } if (indexItem.CreatedUtc.Date == DateTime.MinValue.Date) { return string.Empty; } if (displaySettings.CreatedFormat.Length > 0) { return string.Format( CultureInfo.CurrentCulture, displaySettings.CreatedFormat, TimeZoneInfo.ConvertTimeFromUtc(indexItem.CreatedUtc, timeZone).ToShortDateString()); } return string.Format( CultureInfo.CurrentCulture, Resource.SearchCreatedHtmlFormat, TimeZoneInfo.ConvertTimeFromUtc(indexItem.CreatedUtc, timeZone).ToShortDateString()); }
public string BuildUrl(IndexItem indexItem) { if (indexItem.UseQueryStringParams) { return SiteRoot + "/" + indexItem.ViewPage + "?pageid=" + indexItem.PageId.ToInvariantString() + "&mid=" + indexItem.ModuleId.ToInvariantString() + "&ItemID=" + indexItem.ItemId.ToInvariantString() + indexItem.QueryStringAddendum; } else { return SiteRoot + "/" + indexItem.ViewPage; } }
public static void RemoveForumIndexItem(object oForumThread) { if (WebConfigSettings.DisableSearchIndex) { return; } if (!(oForumThread is ForumThread)) return; ForumThread forumThread = oForumThread as ForumThread; // get list of pages where this module is published List<PageModule> pageModules = PageModule.GetPageModulesByModule(forumThread.ModuleId); // must update index for all pages containing // this module foreach (PageModule pageModule in pageModules) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); // note we are just assigning the properties // needed to derive the key so it can be found and // deleted from the index indexItem.SiteId = forumThread.SiteId; indexItem.PageId = pageModule.PageId; indexItem.ModuleId = forumThread.ModuleId; indexItem.ItemId = forumThread.ForumId; if (ForumConfiguration.AggregateSearchIndexPerThread) { indexItem.QueryStringAddendum = "&thread=" + forumThread.ThreadId.ToInvariantString(); } else { indexItem.QueryStringAddendum = "&thread=" + forumThread.ThreadId.ToInvariantString() + "&postid=" + forumThread.PostId.ToInvariantString(); } mojoPortal.SearchIndex.IndexHelper.RemoveIndex(indexItem); } if (debugLog) { log.Debug("Removed Index "); } }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if ((pageSettings == null) || (indexPath == null)) { if (log.IsErrorEnabled) { log.Error("pageSettings object or index path passed to ForumThreadIndexBuilderProvider.RebuildIndex was null"); } return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("ForumThreadIndexBuilderProvider indexing page - " + pageSettings.PageName); try { List<PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); Guid forumFeatureGuid = new Guid("38aa5a84-9f5c-42eb-8f4c-105983d419fb"); ModuleDefinition forumFeature = new ModuleDefinition(forumFeatureGuid); // new implementation 2012-05-22: get threads by page, then for each thread concat the posts into one item for indexing // previously were indexing individual posts but this makes multiple results in search results for the same thread if (ForumConfiguration.AggregateSearchIndexPerThread) { DataTable threads = ForumThread.GetThreadsByPage( pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in threads.Rows) { StringBuilder threadContent = new StringBuilder(); int threadId = Convert.ToInt32(row["ThreadID"]); DateTime threadDate = Convert.ToDateTime(row["ThreadDate"]); DataTable threadPosts = ForumThread.GetPostsByThread(threadId); foreach (DataRow r in threadPosts.Rows) { threadContent.Append(r["Post"].ToString()); } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } indexItem.CreatedUtc = threadDate; if (row["MostRecentPostDate"] != DBNull.Value) { indexItem.LastModUtc = Convert.ToDateTime(row["MostRecentPostDate"]); } else { indexItem.LastModUtc = threadDate; } indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.FeatureId = forumFeatureGuid.ToString(); indexItem.FeatureName = forumFeature.FeatureName; indexItem.FeatureResourceFile = forumFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"]); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"]); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Subject"].ToString(); indexItem.Content = threadContent.ToString(); if (ForumConfiguration.CombineUrlParams) { indexItem.ViewPage = "Forums/Thread.aspx?pageid=" + pageSettings.PageId.ToInvariantString() + "&t=" + row["ThreadID"].ToString() + "~1"; indexItem.UseQueryStringParams = false; // still need this since it is aprt of the key indexItem.QueryStringAddendum = "&thread=" + row["ThreadID"].ToString(); } else { indexItem.ViewPage = "Forums/Thread.aspx"; indexItem.QueryStringAddendum = "&thread=" + row["ThreadID"].ToString(); } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) log.Debug("Indexed " + indexItem.Title); } } else { //older implementation indexed posts individually DataTable dataTable = ForumThread.GetPostsByPage( pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.FeatureId = forumFeatureGuid.ToString(); indexItem.FeatureName = forumFeature.FeatureName; indexItem.FeatureResourceFile = forumFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"]); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"]); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Subject"].ToString(); indexItem.Content = row["Post"].ToString(); indexItem.ViewPage = "Forums/Thread.aspx"; indexItem.QueryStringAddendum = "&thread=" + row["ThreadID"].ToString() + "&postid=" + row["PostID"].ToString(); // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } //indexItem.PublishBeginDate = Convert.ToDateTime(row["PostDate"]); //indexItem.PublishEndDate = DateTime.MaxValue; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) log.Debug("Indexed " + indexItem.Title); } } } catch (System.Data.Common.DbException ex) { log.Error(ex); } }
private static void IndexItem(Product product) { if (WebConfigSettings.DisableSearchIndex) { return; } if (product == null) { if (log.IsErrorEnabled) { log.Error("product object passed to ProductSearchIndexBuilder.IndexItem was null"); } return; } Store store = new Store(product.StoreGuid); Module module = new Module(store.ModuleId); Guid webStoreFeatureGuid = new Guid("0cefbf18-56de-11dc-8f36-bac755d89593"); ModuleDefinition webStoreFeature = new ModuleDefinition(webStoreFeatureGuid); //// get list of pages where this module is published List <PageModule> pageModules = PageModule.GetPageModulesByModule(store.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( product.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); if (product.SearchIndexPath.Length > 0) { indexItem.IndexPath = product.SearchIndexPath; } indexItem.SiteId = product.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; if (product.Url.Length > 0) { indexItem.ViewPage = product.Url.Replace("~/", string.Empty); indexItem.UseQueryStringParams = false; } else { indexItem.ViewPage = "/WebStore/ProductDetail.aspx"; } indexItem.ItemKey = product.Guid.ToString(); indexItem.ModuleId = store.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = product.Name; indexItem.PageMetaDescription = product.MetaDescription; indexItem.PageMetaKeywords = product.MetaKeywords; indexItem.CreatedUtc = product.Created; indexItem.LastModUtc = product.LastModified; indexItem.Content = product.Teaser + " " + product.Description.Replace(tabScript, string.Empty) + " " + product.MetaDescription + " " + product.MetaKeywords; indexItem.FeatureId = webStoreFeatureGuid.ToString(); indexItem.FeatureName = webStoreFeature.FeatureName; indexItem.FeatureResourceFile = webStoreFeature.ResourceFile; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); } if (debugLog) { log.Debug("Indexed " + product.Name); } }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { bool disableSearchIndex = ConfigHelper.GetBoolProperty("DisableSearchIndex", false); if (disableSearchIndex) { return; } if (pageSettings == null) { log.Error("pageSettings passed in to HtmlContentIndexBuilderProvider.RebuildIndex was null"); return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("HtmlContentIndexBuilderProvider indexing page - " + pageSettings.PageName); try { Guid htmlFeatureGuid = new Guid("881e4e00-93e4-444c-b7b0-6672fb55de10"); ModuleDefinition htmlFeature = new ModuleDefinition(htmlFeatureGuid); List <PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); HtmlRepository repository = new HtmlRepository(); DataTable dataTable = repository.GetHtmlContentByPage( pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { bool includeInSearch = Convert.ToBoolean(row["IncludeInSearch"]); bool excludeFromRecentContent = Convert.ToBoolean(row["ExcludeFromRecentContent"]); IndexItem indexItem = new IndexItem(); indexItem.ExcludeFromRecentContent = excludeFromRecentContent; indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; string authorName = row["CreatedByName"].ToString(); string authorFirstName = row["CreatedByFirstName"].ToString(); string authorLastName = row["CreatedByLastName"].ToString(); if ((authorFirstName.Length > 0) && (authorLastName.Length > 0)) { indexItem.Author = string.Format(CultureInfo.InvariantCulture, Resource.FirstNameLastNameFormat, authorFirstName, authorLastName); } else { indexItem.Author = authorName; } if (!includeInSearch) { indexItem.RemoveOnly = true; } // generally we should not include the page meta because it can result in duplicate results // one for each instance of html content on the page because they all use the smae page meta. // since page meta should reflect the content of the page it is sufficient to just index the content if (WebConfigSettings.IndexPageKeywordsWithHtmlArticleContent) { indexItem.PageMetaDescription = pageSettings.PageMetaDescription; indexItem.PageMetaKeywords = pageSettings.PageMetaKeyWords; } indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); if (pageSettings.UseUrl) { if (pageSettings.UrlHasBeenAdjustedForFolderSites) { indexItem.ViewPage = pageSettings.UnmodifiedUrl.Replace("~/", string.Empty); } else { indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty); } indexItem.UseQueryStringParams = false; } indexItem.FeatureId = htmlFeatureGuid.ToString(); indexItem.FeatureName = htmlFeature.FeatureName; indexItem.FeatureResourceFile = htmlFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"]); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"]); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Title"].ToString(); // added the remove markup 2010-01-30 because some javascript strings like ]]> were apearing in search results if the content conatined jacvascript indexItem.Content = SecurityHelper.RemoveMarkup(row["Body"].ToString()); indexItem.CreatedUtc = Convert.ToDateTime(row["CreatedDate"]); indexItem.LastModUtc = Convert.ToDateTime(row["LastModUtc"]); // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } IndexHelper.RebuildIndex(indexItem, indexPath); log.Debug("Indexed " + indexItem.Title); } } catch (System.Data.Common.DbException ex) { log.Error(ex); } }
public static void RemoveIndex(IndexItem indexItem, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if (indexItem == null) return; if (indexPath == null) return; if (indexPath.Length == 0) return; IndexingQueue queueItem = new IndexingQueue(); queueItem.SiteId = indexItem.SiteId; queueItem.IndexPath = indexPath; queueItem.ItemKey = indexItem.Key; queueItem.RemoveOnly = true; queueItem.SerializedItem = SerializationHelper.SerializeToString(indexItem); queueItem.Save(); // the above queues the items to be indexed. Edit page must also call SiteUtils.QueueIndexing(); after the content is deleted. }
public static List<IndexItem> GetRecentModifiedContent( int siteId, Guid[] featureGuids, DateTime modifiedSinceDate, int maxItems) { int totalHits = 0; List<IndexItem> results = new List<IndexItem>(); using (Lucene.Net.Store.Directory searchDirectory = GetDirectory(siteId)) { Filter filter = null; BooleanQuery filterQuery = new BooleanQuery(); // won't be used to score the results BooleanQuery excludeFilter = new BooleanQuery(); excludeFilter.Add(new TermQuery(new Term("ExcludeFromRecentContent", "false")), Occur.MUST); filterQuery.Add(excludeFilter, Occur.MUST); TermRangeQuery lastModifiedDateFilter = new TermRangeQuery( "LastModUtc", modifiedSinceDate.Date.ToString("s"), DateTime.MaxValue.ToString("s"), true, true); filterQuery.Add(lastModifiedDateFilter, Occur.MUST); // we only want public content, that is both page and module roles must have "All Users" // which means even unauthenticated users Term pageRole = new Term("Role", "All Users"); TermQuery pageRoleFilter = new TermQuery(pageRole); filterQuery.Add(pageRoleFilter, Occur.MUST); Term moduleRole = new Term("ModuleRole", "All Users"); TermQuery moduleRoleFilter = new TermQuery(moduleRole); filterQuery.Add(moduleRoleFilter, Occur.MUST); if ((featureGuids != null)&&(featureGuids.Length > 0)) { BooleanQuery featureFilter = new BooleanQuery(); foreach (Guid featureGuid in featureGuids) { featureFilter.Add(new TermQuery(new Term("FeatureId", featureGuid.ToString())), Occur.SHOULD); } filterQuery.Add(featureFilter, Occur.MUST); } filter = new QueryWrapperFilter(filterQuery); // filterQuery won't affect result scores MatchAllDocsQuery matchAllQuery = new MatchAllDocsQuery(); using (IndexSearcher searcher = new IndexSearcher(searchDirectory)) { int maxResults = int.MaxValue; TopDocs hits = searcher.Search(matchAllQuery, filter, maxResults); totalHits = hits.TotalHits; for (int i = 0; i < totalHits; i++) { Document doc = searcher.Doc(hits.ScoreDocs[i].Doc); IndexItem indexItem = new IndexItem(doc, hits.ScoreDocs[i].Score); results.Add(indexItem); } } } // sort all descending on lastmodutc results.Sort(); if (results.Count <= maxItems) { return results; } else { List<IndexItem> finalResults = new List<IndexItem>(); for (int i = 0; i < maxItems; i++) { finalResults.Add(results[i]); } return finalResults; } }
public string FormatModifiedDate(IndexItem indexItem) { if ((!displaySettings.ShowLastModDate) || (!config.ShowLastModDate) || (timeZone == null)) { return string.Empty; } if (indexItem.LastModUtc.Date == DateTime.MinValue.Date) { return string.Empty; } if (displaySettings.ModifiedFormat.Length > 0) { return string.Format( CultureInfo.CurrentCulture, displaySettings.ModifiedFormat, TimeZoneInfo.ConvertTimeFromUtc(indexItem.LastModUtc, timeZone).ToString(displaySettings.DateFormat)); } return string.Format( CultureInfo.CurrentCulture, Resource.SearchModifiedHtmlFormat, TimeZoneInfo.ConvertTimeFromUtc(indexItem.LastModUtc, timeZone).ToString(displaySettings.DateFormat)); }
private void ProcessQueue(DataTable q, int siteId, string indexPath) { rowsProcessed = 0; rowsToProcess = q.Rows.Count; // first process deletes with reader try { using (Lucene.Net.Store.Directory searchDirectory = IndexHelper.GetDirectory(siteId)) { using (IndexReader reader = IndexReader.Open(searchDirectory, false)) { foreach (DataRow row in q.Rows) { Term term = new Term("Key", row["ItemKey"].ToString()); try { reader.DeleteDocuments(term); log.Debug("reader.DeleteDocuments(term) for Key " + row["ItemKey"].ToString()); } catch (Exception ge) { // TODO: monitor what real exceptions if any occur and then // change this catch to catch only the expected ones // instead of non specific exception log.Error(ge); } bool removeOnly = Convert.ToBoolean(row["RemoveOnly"]); if (removeOnly) { Int64 rowId = Convert.ToInt64(row["RowId"]); IndexingQueue.Delete(rowId); } if (DateTime.UtcNow > nextStatusUpdateTime) { // don't mark as complete because there may be more qu items //for different index paths in a multi site installation bool markAsComplete = false; ReportStatus(markAsComplete); } } } } } catch (System.IO.IOException ex) { log.Info("IndexWriter swallowed exception this is expected if building or rebuilding the search index ", ex); errorCount += 1; } catch (TypeInitializationException ex) { log.Info("IndexWriter swallowed exception ", ex); errorCount += 1; } // next add items with writer using (Lucene.Net.Store.Directory searchDirectory = IndexHelper.GetDirectory(siteId)) { using (IndexWriter indexWriter = GetWriter(siteId, searchDirectory)) { if (indexWriter == null) { log.Error("failed to get IndexWriter for path: " + indexPath); errorCount += 1; return; } foreach (DataRow row in q.Rows) { bool removeOnly = Convert.ToBoolean(row["RemoveOnly"]); if (!removeOnly) { try { IndexItem indexItem = (IndexItem)SerializationHelper.DeserializeFromString(typeof(IndexItem), row["SerializedItem"].ToString()); // if the content is locked down to only admins it is a special case // we just won't add it to the search index // because at search time we avoid the role check for all admins, content admins and siteeditors // we don't have a good way to prevent content admins and site editors from seeing the content // in search if ((indexItem.ViewRoles != "Admins;") && (indexItem.ModuleViewRoles != "Admins;")) { if (indexItem.ViewPage.Length > 0) { Document doc = GetDocument(indexItem); WriteToIndex(doc, indexWriter); log.Debug("called WriteToIndex(doc, indexWriter) for key " + indexItem.Key); } } Int64 rowId = Convert.ToInt64(row["RowId"]); IndexingQueue.Delete(rowId); } catch (Exception ex) { log.Error(ex); } } if (DateTime.UtcNow > nextStatusUpdateTime) { // don't mark as complete because there may be more qu items //for different index paths in a multi site installation bool markAsComplete = false; ReportStatus(markAsComplete); } } try { indexWriter.Optimize(); } catch (System.IO.IOException ex) { log.Error(ex); } } } }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if (pageSettings == null) { log.Error("LinksIndexBuilderProvider.RebuildIndex error: pageSettings was null "); return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("LinksIndexBuilderProvider indexing page - " + pageSettings.PageName); try { Guid linksFeatureGuid = new Guid("74bdbcc2-0e79-47ff-bcd4-a159270bf36e"); ModuleDefinition linksFeature = new ModuleDefinition(linksFeatureGuid); List <PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); DataTable dataTable = Link.GetLinksByPage( pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.CreatedUtc = Convert.ToDateTime(row["CreatedDate"]); indexItem.LastModUtc = indexItem.CreatedUtc; if (pageSettings.UseUrl) { if (pageSettings.UrlHasBeenAdjustedForFolderSites) { indexItem.ViewPage = pageSettings.UnmodifiedUrl.Replace("~/", string.Empty); } else { indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty); } indexItem.UseQueryStringParams = false; } indexItem.FeatureId = linksFeatureGuid.ToString(); indexItem.FeatureName = linksFeature.FeatureName; indexItem.FeatureResourceFile = linksFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"], CultureInfo.InvariantCulture); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"], CultureInfo.InvariantCulture); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Title"].ToString(); indexItem.Content = row["Description"].ToString(); // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) { log.Debug("Indexed " + indexItem.Title); } } } catch (System.Data.Common.DbException ex) { log.Error(ex); } }
private static void IndexItem(Link link) { if (WebConfigSettings.DisableSearchIndex) { return; } SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { if (log.IsErrorEnabled) { log.Error("Link object passed to Links.IndexItem was null"); } return; } if (link == null) { return; } Guid linksFeatureGuid = new Guid("74bdbcc2-0e79-47ff-bcd4-a159270bf36e"); ModuleDefinition linksFeature = new ModuleDefinition(linksFeatureGuid); Module module = new Module(link.ModuleId); // get list of pages where this module is published List <PageModule> pageModules = PageModule.GetPageModulesByModule(link.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( siteSettings.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = siteSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; indexItem.FeatureId = linksFeatureGuid.ToString(); indexItem.FeatureName = linksFeature.FeatureName; indexItem.FeatureResourceFile = linksFeature.ResourceFile; indexItem.ItemId = link.ItemId; indexItem.ModuleId = link.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = link.Title; indexItem.Content = link.Description; indexItem.CreatedUtc = link.CreatedDate; indexItem.LastModUtc = link.CreatedDate; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); } if (debugLog) { log.Debug("Indexed " + link.Title); } }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if (pageSettings == null) { return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("CalendarEventIndexBuilderProvider indexing page - " + pageSettings.PageName); try { Guid calendarFeatureGuid = new Guid("c5e6a5df-ac2a-43d3-bb7f-9739bc47194e"); ModuleDefinition calendarFeature = new ModuleDefinition(calendarFeatureGuid); List <PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); DataTable dataTable = CalendarEvent.GetEventsByPage(pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.PageIndex = pageSettings.PageIndex; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.FeatureId = calendarFeatureGuid.ToString(); indexItem.FeatureName = calendarFeature.FeatureName; indexItem.FeatureResourceFile = calendarFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"], CultureInfo.InvariantCulture); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"], CultureInfo.InvariantCulture); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Title"].ToString(); indexItem.Content = row["Description"].ToString(); indexItem.ViewPage = "EventCalendar/EventDetails.aspx"; indexItem.CreatedUtc = Convert.ToDateTime(row["CreatedDate"]); indexItem.LastModUtc = Convert.ToDateTime(row["LastModUtc"]); // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) { log.Debug("Indexed " + indexItem.Title); } } } catch (System.Data.Common.DbException ex) { log.Error(ex); } }
private static void IndexItem(CalendarEvent calendarEvent) { if (WebConfigSettings.DisableSearchIndex) { return; } if (calendarEvent == null) { return; } try { //SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); //if ((siteSettings == null) // || (calendarEvent == null)) //{ // return; //} Module module = new Module(calendarEvent.ModuleId); Guid calendarFeatureGuid = new Guid("c5e6a5df-ac2a-43d3-bb7f-9739bc47194e"); ModuleDefinition calendarFeature = new ModuleDefinition(calendarFeatureGuid); // get list of pages where this module is published List <PageModule> pageModules = PageModule.GetPageModulesByModule(calendarEvent.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( calendarEvent.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); if (calendarEvent.SearchIndexPath.Length > 0) { indexItem.IndexPath = calendarEvent.SearchIndexPath; } indexItem.SiteId = calendarEvent.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; indexItem.ItemId = calendarEvent.ItemId; indexItem.ModuleId = calendarEvent.ModuleId; indexItem.ViewPage = "EventCalendar/EventDetails.aspx"; indexItem.FeatureId = calendarFeatureGuid.ToString(); indexItem.FeatureName = calendarFeature.FeatureName; indexItem.FeatureResourceFile = calendarFeature.ResourceFile; indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = calendarEvent.Title; indexItem.Content = calendarEvent.Description; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; indexItem.CreatedUtc = calendarEvent.CreatedDate; indexItem.LastModUtc = calendarEvent.LastModUtc; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); } if (debugLog) { log.Debug("Indexed " + calendarEvent.Title); } } catch (System.Data.Common.DbException ex) { log.Error("CalendarEventIndexBuilderProvider.IndexItem", ex); } }
private static void IndexItem(Schedule scheduleThread) { if (WebConfigSettings.DisableSearchIndex) { return; } if (scheduleThread == null) { if (log.IsErrorEnabled) { log.Error("forumThread object passed in SchedulePageIndexBuilderProvider.IndexItem was null"); } return; } Schedule sched = new Schedule(scheduleThread.ScheduleId); Module module = new Module(scheduleThread.ModuleId); Guid scheduleFeatureGuid = new Guid("ca4ecf9b-22be-4be2-ac66-36e0e625dbed"); ModuleDefinition forumFeature = new ModuleDefinition(scheduleFeatureGuid); // get list of pages where this module is published List <PageModule> pageModules = PageModule.GetPageModulesByModule(scheduleThread.ModuleId); // must update index for all pages containing // this module foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( scheduleThread.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); if (scheduleThread.SearchIndexPath.Length > 0) { indexItem.IndexPath = scheduleThread.SearchIndexPath; } indexItem.SiteId = scheduleThread.SiteId; indexItem.PageId = pageModule.PageId; indexItem.PageName = pageSettings.PageName; // permissions are kept in sync in search index // so that results are filtered by role correctly indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; indexItem.ItemId = scheduleThread.ScheduleId; indexItem.ModuleId = scheduleThread.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.FeatureId = scheduleFeatureGuid.ToString(); indexItem.FeatureName = forumFeature.FeatureName; indexItem.FeatureResourceFile = forumFeature.ResourceFile; indexItem.Title = scheduleThread.Title; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; indexItem.ViewPage = WebConfigSettings.CoursesUrl; indexItem.CreatedUtc = scheduleThread.CreatedOn; indexItem.LastModUtc = scheduleThread.UpdatedOn; //older implementation indexItem.Content = scheduleThread.Description; //indexItem.QueryStringAddendum = "&thread=" // + forumThread.ThreadId.ToString() // + "&postid=" + forumThread.PostId.ToString(); mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); if (debugLog) { log.Debug("Indexed " + scheduleThread.Title); } } }
private Document GetDocument(IndexItem indexItem) { Document doc = new Document(); // searchable fields doc.Add(new Field("Key", indexItem.Key, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Author", indexItem.Author, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("SiteID", indexItem.SiteId.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("ViewRoles", indexItem.ViewRoles, Field.Store.YES, Field.Index.NO)); string[] roles = indexItem.ViewRoles.Split(';'); foreach (string role in roles) { if (role.Length > 0) { doc.Add(new Field("Role", role, Field.Store.YES, Field.Index.NOT_ANALYZED)); } } roles = indexItem.ModuleViewRoles.Split(';'); foreach (string role in roles) { if (role.Length > 0) { doc.Add(new Field("ModuleRole", role, Field.Store.YES, Field.Index.NOT_ANALYZED)); } } doc.Add(new Field("FeatureId", indexItem.FeatureId, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("PageID", indexItem.PageId.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("ModuleID", indexItem.ModuleId.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("ItemID", indexItem.ItemId.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("PublishBeginDate", indexItem.PublishBeginDate.ToString("s"), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("PublishEndDate", indexItem.PublishEndDate.ToString("s"), Field.Store.YES, Field.Index.NOT_ANALYZED)); //doc.Add(new Field("IndexedUtc", DateTime.UtcNow.ToString("s"), Field.Store.YES, Field.Index.NOT_ANALYZED)); //doc.Add(new NumericField("PubBeginDate", Field.Store.YES, true).SetLongValue(indexItem.PublishBeginDate.Ticks)); //doc.Add(new NumericField("PubEndDate", Field.Store.YES, true).SetLongValue(indexItem.PublishEndDate.Ticks)); //2013-01-08 adding created and lastmod date and storage to Numeric field for sorting and range queries //http://stackoverflow.com/questions/2685490/lucene-net-sorting-by-int //if (indexItem.CreatedUtc > DateTime.MinValue) //{ // doc.Add(new NumericField("CreatedUtc", Field.Store.YES, true).SetLongValue(indexItem.CreatedUtc.Ticks)); //} //else //{ // doc.Add(new NumericField("CreatedUtc", Field.Store.YES, true).SetLongValue(DateTime.UtcNow.Ticks)); //} //if (indexItem.LastModUtc > DateTime.MinValue) //{ // doc.Add(new NumericField("LastModUtc", Field.Store.YES, true).SetLongValue(indexItem.LastModUtc.Ticks)); //} //else //{ // doc.Add(new NumericField("LastModUtc", Field.Store.YES, true).SetLongValue(DateTime.UtcNow.Ticks)); //} doc.Add(new Field("CreatedUtc", indexItem.CreatedUtc.ToString("s"), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("LastModUtc", indexItem.LastModUtc.ToString("s"), Field.Store.YES, Field.Index.NOT_ANALYZED)); //doc.Add(new NumericField("CreatedUtc", Field.Store.YES, true).SetIntValue(indexItem.CreatedUtc.ToDateInteger())); //doc.Add(new NumericField("LastModUtc", Field.Store.YES, true).SetIntValue(indexItem.LastModUtc.ToDateInteger())); doc.Add(new Field("PageName", indexItem.PageName, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); doc.Add(new Field("ModuleTitle", indexItem.ModuleTitle, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); doc.Add(new Field("Title", indexItem.Title, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); doc.Add(new Field("PageMetaDesc", indexItem.PageMetaDescription, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); string[] keywords = indexItem.PageMetaKeywords.Split(','); foreach (string word in keywords) { if (word.Trim().Length > 0) { doc.Add(new Field("Keyword", word.Trim(), Field.Store.YES, Field.Index.NOT_ANALYZED)); } } // TODO: store an abstract that can be displayed in alternate to intro and contain raw html string introContent = ConvertToText(indexItem.Content); if (introContent.Length > WebConfigSettings.SearchResultsFragmentSize) { introContent = UIHelper.CreateExcerpt(introContent, (WebConfigSettings.SearchResultsFragmentSize - 3)) + "..."; } doc.Add(new Field("Intro", introContent, Field.Store.YES, Field.Index.NOT_ANALYZED)); //doc.Add(new Field("Intro", // (textContent.Length < WebConfigSettings.SearchResultsFragmentSize ? textContent : (UIHelper.CreateExcerpt(textContent, (WebConfigSettings.SearchResultsFragmentSize -3)) + "...")) // , Field.Store.YES, Field.Index.NOT_ANALYZED // ) // ); // for display in recent content features, html is allowed here if (indexItem.ContentAbstract.Length == 0) { indexItem.ContentAbstract = introContent; } doc.Add(new Field("Abstract", indexItem.ContentAbstract, Field.Store.YES, Field.Index.NO)); //// other content is optional, used for blog comments //// could be used elsewhere //if (storeContentForResultsHighlighting) //{ // this is the main searched field doc.Add(new Field("contents", ConvertToText(indexItem.Content) + " " + ConvertToText(indexItem.OtherContent), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); //} //else //{ // doc.Add(new Field("contents", textContent + " " // + ConvertToText(indexItem.OtherContent), Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.YES)); //} //unsearchable fields doc.Add(new Field("Feature", indexItem.FeatureName, Field.Store.YES, Field.Index.NO)); doc.Add(new Field("FeatureResourceFile", indexItem.FeatureResourceFile, Field.Store.YES, Field.Index.NO)); doc.Add(new Field("PageNumber", indexItem.PageNumber.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NO)); doc.Add(new Field("ViewPage", indexItem.ViewPage, Field.Store.YES, Field.Index.NO)); doc.Add(new Field("UseQueryStringParams", indexItem.UseQueryStringParams.ToString(), Field.Store.YES, Field.Index.NO)); doc.Add(new Field("QueryStringAddendum", indexItem.QueryStringAddendum, Field.Store.YES, Field.Index.NO)); doc.Add(new Field("ExcludeFromRecentContent", indexItem.ExcludeFromRecentContent.ToString().ToLower(), Field.Store.YES, Field.Index.NOT_ANALYZED)); return doc; }
public void Add(IndexItem item) { this.List.Add(item); }
private Document GetDocument(IndexItem indexItem) { Document doc = new Document(); // searchable fields doc.Add(new Field("Key", indexItem.Key, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Author", indexItem.Author, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("SiteID", indexItem.SiteId.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("ViewRoles", indexItem.ViewRoles, Field.Store.YES, Field.Index.NO)); string[] roles = indexItem.ViewRoles.Split(';'); foreach (string role in roles) { if (role.Length > 0) { doc.Add(new Field("Role", role, Field.Store.YES, Field.Index.NOT_ANALYZED)); } } roles = indexItem.ModuleViewRoles.Split(';'); foreach (string role in roles) { if (role.Length > 0) { doc.Add(new Field("ModuleRole", role, Field.Store.YES, Field.Index.NOT_ANALYZED)); } } doc.Add(new Field("FeatureId", indexItem.FeatureId, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("PageID", indexItem.PageId.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("ModuleID", indexItem.ModuleId.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("ItemID", indexItem.ItemId.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("PublishBeginDate", indexItem.PublishBeginDate.ToString("s"), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("PublishEndDate", indexItem.PublishEndDate.ToString("s"), Field.Store.YES, Field.Index.NOT_ANALYZED)); //doc.Add(new Field("IndexedUtc", DateTime.UtcNow.ToString("s"), Field.Store.YES, Field.Index.NOT_ANALYZED)); //doc.Add(new NumericField("PubBeginDate", Field.Store.YES, true).SetLongValue(indexItem.PublishBeginDate.Ticks)); //doc.Add(new NumericField("PubEndDate", Field.Store.YES, true).SetLongValue(indexItem.PublishEndDate.Ticks)); //2013-01-08 adding created and lastmod date and storage to Numeric field for sorting and range queries //http://stackoverflow.com/questions/2685490/lucene-net-sorting-by-int //if (indexItem.CreatedUtc > DateTime.MinValue) //{ // doc.Add(new NumericField("CreatedUtc", Field.Store.YES, true).SetLongValue(indexItem.CreatedUtc.Ticks)); //} //else //{ // doc.Add(new NumericField("CreatedUtc", Field.Store.YES, true).SetLongValue(DateTime.UtcNow.Ticks)); //} //if (indexItem.LastModUtc > DateTime.MinValue) //{ // doc.Add(new NumericField("LastModUtc", Field.Store.YES, true).SetLongValue(indexItem.LastModUtc.Ticks)); //} //else //{ // doc.Add(new NumericField("LastModUtc", Field.Store.YES, true).SetLongValue(DateTime.UtcNow.Ticks)); //} doc.Add(new Field("CreatedUtc", indexItem.CreatedUtc.ToString("s"), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("LastModUtc", indexItem.LastModUtc.ToString("s"), Field.Store.YES, Field.Index.NOT_ANALYZED)); //doc.Add(new NumericField("CreatedUtc", Field.Store.YES, true).SetIntValue(indexItem.CreatedUtc.ToDateInteger())); //doc.Add(new NumericField("LastModUtc", Field.Store.YES, true).SetIntValue(indexItem.LastModUtc.ToDateInteger())); doc.Add(new Field("PageName", indexItem.PageName, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); doc.Add(new Field("ModuleTitle", indexItem.ModuleTitle, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); doc.Add(new Field("Title", indexItem.Title, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); doc.Add(new Field("PageMetaDesc", indexItem.PageMetaDescription, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); string[] keywords = indexItem.PageMetaKeywords.Split(','); foreach (string word in keywords) { if (word.Trim().Length > 0) { doc.Add(new Field("Keyword", word.Trim(), Field.Store.YES, Field.Index.NOT_ANALYZED)); } } // TODO: store an abstract that can be displayed in alternate to intro and contain raw html string introContent = ConvertToText(indexItem.Content); if (introContent.Length > WebConfigSettings.SearchResultsFragmentSize) { introContent = UIHelper.CreateExcerpt(introContent, (WebConfigSettings.SearchResultsFragmentSize - 3)) + "..."; } doc.Add(new Field("Intro", introContent, Field.Store.YES, Field.Index.NOT_ANALYZED)); //doc.Add(new Field("Intro", // (textContent.Length < WebConfigSettings.SearchResultsFragmentSize ? textContent : (UIHelper.CreateExcerpt(textContent, (WebConfigSettings.SearchResultsFragmentSize -3)) + "...")) // , Field.Store.YES, Field.Index.NOT_ANALYZED // ) // ); // for display in recent content features, html is allowed here if (indexItem.ContentAbstract.Length == 0) { indexItem.ContentAbstract = introContent; } doc.Add(new Field("Abstract", indexItem.ContentAbstract, Field.Store.YES, Field.Index.NO)); //// other content is optional, used for blog comments //// could be used elsewhere //if (storeContentForResultsHighlighting) //{ // this is the main searched field doc.Add(new Field("contents", ConvertToText(indexItem.Content) + " " + ConvertToText(indexItem.OtherContent), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); //} //else //{ // doc.Add(new Field("contents", textContent + " " // + ConvertToText(indexItem.OtherContent), Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.YES)); //} //unsearchable fields doc.Add(new Field("Feature", indexItem.FeatureName, Field.Store.YES, Field.Index.NO)); doc.Add(new Field("FeatureResourceFile", indexItem.FeatureResourceFile, Field.Store.YES, Field.Index.NO)); doc.Add(new Field("PageNumber", indexItem.PageNumber.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NO)); doc.Add(new Field("ViewPage", indexItem.ViewPage, Field.Store.YES, Field.Index.NO)); doc.Add(new Field("UseQueryStringParams", indexItem.UseQueryStringParams.ToString(), Field.Store.YES, Field.Index.NO)); doc.Add(new Field("QueryStringAddendum", indexItem.QueryStringAddendum, Field.Store.YES, Field.Index.NO)); doc.Add(new Field("ExcludeFromRecentContent", indexItem.ExcludeFromRecentContent.ToString().ToLower(), Field.Store.YES, Field.Index.NOT_ANALYZED)); return(doc); }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { bool disableSearchIndex = ConfigHelper.GetBoolProperty("DisableSearchIndex", false); if (disableSearchIndex) { return; } if (pageSettings == null) { log.Error("pageSettings passed in to HtmlContentIndexBuilderProvider.RebuildIndex was null"); return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("HtmlContentIndexBuilderProvider indexing page - " + pageSettings.PageName); try { Guid htmlFeatureGuid = new Guid("881e4e00-93e4-444c-b7b0-6672fb55de10"); ModuleDefinition htmlFeature = new ModuleDefinition(htmlFeatureGuid); List<PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); HtmlRepository repository = new HtmlRepository(); DataTable dataTable = repository.GetHtmlContentByPage( pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { bool includeInSearch = Convert.ToBoolean(row["IncludeInSearch"]); bool excludeFromRecentContent = Convert.ToBoolean(row["ExcludeFromRecentContent"]); IndexItem indexItem = new IndexItem(); indexItem.ExcludeFromRecentContent = excludeFromRecentContent; indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; string authorName = row["CreatedByName"].ToString(); string authorFirstName = row["CreatedByFirstName"].ToString(); string authorLastName = row["CreatedByLastName"].ToString(); if ((authorFirstName.Length > 0) && (authorLastName.Length > 0)) { indexItem.Author = string.Format(CultureInfo.InvariantCulture, Resource.FirstNameLastNameFormat, authorFirstName, authorLastName); } else { indexItem.Author = authorName; } if (!includeInSearch) { indexItem.RemoveOnly = true; } // generally we should not include the page meta because it can result in duplicate results // one for each instance of html content on the page because they all use the smae page meta. // since page meta should reflect the content of the page it is sufficient to just index the content if (WebConfigSettings.IndexPageKeywordsWithHtmlArticleContent) { indexItem.PageMetaDescription = pageSettings.PageMetaDescription; indexItem.PageMetaKeywords = pageSettings.PageMetaKeyWords; } indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); if (pageSettings.UseUrl) { if (pageSettings.UrlHasBeenAdjustedForFolderSites) { indexItem.ViewPage = pageSettings.UnmodifiedUrl.Replace("~/", string.Empty); } else { indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty); } indexItem.UseQueryStringParams = false; } indexItem.FeatureId = htmlFeatureGuid.ToString(); indexItem.FeatureName = htmlFeature.FeatureName; indexItem.FeatureResourceFile = htmlFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"]); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"]); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Title"].ToString(); // added the remove markup 2010-01-30 because some javascript strings like ]]> were apearing in search results if the content conatined jacvascript indexItem.Content = SecurityHelper.RemoveMarkup(row["Body"].ToString()); indexItem.CreatedUtc = Convert.ToDateTime(row["CreatedDate"]); indexItem.LastModUtc = Convert.ToDateTime(row["LastModUtc"]); // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } IndexHelper.RebuildIndex(indexItem, indexPath); log.Debug("Indexed " + indexItem.Title); } } catch (System.Data.Common.DbException ex) { log.Error(ex); } }
private static void IndexItem(SharedFile sharedFile) { if (WebConfigSettings.DisableSearchIndex) { return; } SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if ( (sharedFile == null) || (siteSettings == null) ) { return; } Guid sharedFilesFeatureGuid = new Guid("dc873d76-5bf2-4ac5-bff7-434a87a3fc8e"); ModuleDefinition sharedFilesFeature = new ModuleDefinition(sharedFilesFeatureGuid); Module module = new Module(sharedFile.ModuleId); // get list of pages where this module is published List <PageModule> pageModules = PageModule.GetPageModulesByModule(sharedFile.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( siteSettings.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = siteSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; indexItem.FeatureId = sharedFilesFeatureGuid.ToString(); indexItem.FeatureName = sharedFilesFeature.FeatureName; indexItem.FeatureResourceFile = sharedFilesFeature.ResourceFile; indexItem.CreatedUtc = sharedFile.UploadDate; indexItem.LastModUtc = sharedFile.UploadDate; indexItem.ItemId = sharedFile.ItemId; indexItem.ModuleId = sharedFile.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = sharedFile.FriendlyName.Replace("_", " ").Replace("-", " ").Replace(".", " "); indexItem.Content = sharedFile.Description; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; // make the search results a download link indexItem.ViewPage = "SharedFiles/Download.aspx?pageid=" + indexItem.PageId.ToInvariantString() + "&fileid=" + indexItem.ItemId.ToInvariantString() + "&mid=" + indexItem.ModuleId.ToInvariantString(); indexItem.UseQueryStringParams = false; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); } if (debugLog) { log.Debug("Indexed " + sharedFile.FriendlyName); } }
public static void RemoveIndex(IndexItem indexItem) { if (WebConfigSettings.DisableSearchIndex) { return; } if (indexItem == null) return; if (indexItem.IndexPath.Length > 0) { RemoveIndex(indexItem, indexItem.IndexPath); return; } indexItem.IndexPath = GetSearchIndexPath(indexItem.SiteId); RemoveIndex(indexItem, indexItem.IndexPath); return; }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if ((pageSettings == null) || (indexPath == null)) { return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("SharedFilesIndexBuilderProvider indexing page - " + pageSettings.PageName); try { Guid sharedFilesFeatureGuid = new Guid("dc873d76-5bf2-4ac5-bff7-434a87a3fc8e"); ModuleDefinition sharedFilesFeature = new ModuleDefinition(sharedFilesFeatureGuid); List <PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); DataTable dataTable = SharedFile.GetSharedFilesByPage(pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.CreatedUtc = Convert.ToDateTime(row["UploadDate"]); indexItem.LastModUtc = indexItem.CreatedUtc; //if (pageSettings.UseUrl) //{ // if (pageSettings.UrlHasBeenAdjustedForFolderSites) // { // indexItem.ViewPage = pageSettings.UnmodifiedUrl.Replace("~/", string.Empty); // } // else // { // indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty); // } // indexItem.UseQueryStringParams = false; //} indexItem.FeatureId = sharedFilesFeatureGuid.ToString(); indexItem.FeatureName = sharedFilesFeature.FeatureName; indexItem.FeatureResourceFile = sharedFilesFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"]); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"]); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["FriendlyName"].ToString().Replace("_", " ").Replace("-", " ").Replace(".", " "); indexItem.Content = row["Description"].ToString(); // make the search results a download link indexItem.ViewPage = "SharedFiles/Download.aspx?pageid=" + indexItem.PageId.ToInvariantString() + "&fileid=" + indexItem.ItemId.ToInvariantString() + "&mid=" + indexItem.ModuleId.ToInvariantString(); indexItem.UseQueryStringParams = false; // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) { log.Debug("Indexed " + indexItem.Title); } } } catch (System.Data.Common.DbException ex) { log.Error(ex); } }
public static void RemoveIndexItem( int siteId, int pageId, int moduleId, int itemId, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } IndexItem indexItem = new IndexItem(); indexItem.SiteId = siteId; indexItem.PageId = pageId; indexItem.ModuleId = moduleId; indexItem.ItemId = itemId; indexItem.IndexPath = indexPath; RemoveIndex(indexItem); if (debugLog) log.Debug("Removed Index "); }
private static void IndexItem(CourseModule courseModule) { if (WebConfigSettings.DisableSearchIndex) { return; } if (courseModule == null) { if (log.IsErrorEnabled) { log.Error("forumThread object passed in BrowseCoursesIndexBuilderProvider.IndexItem was null"); } return; } CourseModule courMod = new CourseModule(courseModule.CourseId); Module module = new Module(courseModule.ModuleId); Guid scheduleFeatureGuid = new Guid("dc873d76-5bf2-4ac5-bff7-434a86a3fc9e"); ModuleDefinition forumFeature = new ModuleDefinition(scheduleFeatureGuid); // get list of pages where this module is published List <PageModule> pageModules = PageModule.GetPageModulesByModule(courseModule.ModuleId); // must update index for all pages containing // this module foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( courseModule.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); if (courseModule.SearchIndexPath.Length > 0) { indexItem.IndexPath = courseModule.SearchIndexPath; } indexItem.SiteId = courseModule.SiteId; indexItem.PageId = pageModule.PageId; indexItem.PageName = pageSettings.PageName; // permissions are kept in sync in search index // so that results are filtered by role correctly indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; indexItem.ItemId = courseModule.CourseId; indexItem.ModuleId = courseModule.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.FeatureId = scheduleFeatureGuid.ToString(); indexItem.FeatureName = forumFeature.FeatureName; indexItem.FeatureResourceFile = forumFeature.ResourceFile; indexItem.Title = courseModule.CourseName; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; indexItem.ViewPage = WebConfigSettings.CourseSearchUrl; //"browse-course"; indexItem.Content = courseModule.Description + " " + courseModule.Metatags + " " + courseModule.LeadInstructor; //indexItem.CreatedUtc = courseModule.CreatedOn; //indexItem.LastModUtc = courseModule.UpdatedOn; //older implementation //indexItem.Content = scheduleThread.PostMessage; //indexItem.QueryStringAddendum = "&thread=" // + forumThread.ThreadId.ToString() // + "&postid=" + forumThread.PostId.ToString(); mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); if (debugLog) { log.Debug("Indexed " + courseModule.CourseName); } } }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if ((pageSettings == null) || (indexPath == null)) { return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("SharedFilesIndexBuilderProvider indexing page - " + pageSettings.PageName); try { Guid sharedFilesFeatureGuid = new Guid("dc873d76-5bf2-4ac5-bff7-434a87a3fc8e"); ModuleDefinition sharedFilesFeature = new ModuleDefinition(sharedFilesFeatureGuid); List<PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); DataTable dataTable = SharedFile.GetSharedFilesByPage(pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.CreatedUtc = Convert.ToDateTime(row["UploadDate"]); indexItem.LastModUtc = indexItem.CreatedUtc; //if (pageSettings.UseUrl) //{ // if (pageSettings.UrlHasBeenAdjustedForFolderSites) // { // indexItem.ViewPage = pageSettings.UnmodifiedUrl.Replace("~/", string.Empty); // } // else // { // indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty); // } // indexItem.UseQueryStringParams = false; //} indexItem.FeatureId = sharedFilesFeatureGuid.ToString(); indexItem.FeatureName = sharedFilesFeature.FeatureName; indexItem.FeatureResourceFile = sharedFilesFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"]); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"]); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["FriendlyName"].ToString().Replace("_", " ").Replace("-", " ").Replace(".", " "); indexItem.Content = row["Description"].ToString(); // make the search results a download link indexItem.ViewPage = "SharedFiles/Download.aspx?pageid=" + indexItem.PageId.ToInvariantString() + "&fileid=" + indexItem.ItemId.ToInvariantString() + "&mid=" + indexItem.ModuleId.ToInvariantString(); indexItem.UseQueryStringParams = false; // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) log.Debug("Indexed " + indexItem.Title); } } catch (System.Data.Common.DbException ex) { log.Error(ex); } }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if ((pageSettings == null) || (indexPath == null)) { if (log.IsErrorEnabled) { log.Error("pageSettings object or index path passed to BrowseCoursesIndexBuilderProvider.RebuildIndex was null"); } return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("BrowseCoursesIndexBuilderProvider indexing page - " + pageSettings.PageName); try { List <PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); Guid scheduleFeatureGuid = new Guid("dc873d76-5bf2-4ac5-bff7-434a86a3fc9e"); ModuleDefinition forumFeature = new ModuleDefinition(scheduleFeatureGuid); List <CourseModule> lstSchedules = CourseModule.GetCoursesByPage(pageSettings.SiteId, pageSettings.PageId); DataTable dataTable = ConvertToDatatable(lstSchedules); foreach (DataRow row in dataTable.Rows) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.FeatureId = scheduleFeatureGuid.ToString(); indexItem.FeatureName = forumFeature.FeatureName; indexItem.FeatureResourceFile = forumFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["CourseID"]); indexItem.ModuleId = Convert.ToInt32(row["ModuleId"]); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["CourseName"].ToString(); indexItem.Content = row["Description"].ToString() + " " + row["Metatags"].ToString() + " " + row["LeadInstructor"].ToString(); indexItem.ViewPage = WebConfigSettings.CourseSearchUrl; //"browse-course"; // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } //indexItem.PublishBeginDate = Convert.ToDateTime(row["PostDate"]); //indexItem.PublishEndDate = DateTime.MaxValue; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) { log.Debug("Indexed " + indexItem.Title); } } } catch (System.Data.Common.DbException ex) { log.Error(ex); } }
/// <summary> /// This method is called when the site index is rebuilt /// </summary> /// <param name="pageSettings"></param> /// <param name="indexPath"></param> public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if (pageSettings == null) { log.Error("pageSettings object passed to ProductSearchIndexBuilder.RebuildIndex was null"); return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("ProductSearchIndexBuilder indexing page - " + pageSettings.PageName); Guid webStoreFeatureGuid = new Guid("0cefbf18-56de-11dc-8f36-bac755d89593"); ModuleDefinition webStoreFeature = new ModuleDefinition(webStoreFeatureGuid); List <PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); // adding a try catch here because this is invoked even for non-implemented db platforms and it causes an error try { DataTable dataTable = Product.GetBySitePage( pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.FeatureId = webStoreFeatureGuid.ToString(); indexItem.FeatureName = webStoreFeature.FeatureName; indexItem.FeatureResourceFile = webStoreFeature.ResourceFile; indexItem.ItemKey = row["Guid"].ToString(); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"], CultureInfo.InvariantCulture); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Name"].ToString(); indexItem.ViewPage = row["Url"].ToString().Replace("/", string.Empty); if (indexItem.ViewPage.Length > 0) { indexItem.UseQueryStringParams = false; } else { indexItem.ViewPage = "WebStore/ProductDetail.aspx"; } indexItem.PageMetaDescription = row["MetaDescription"].ToString(); indexItem.PageMetaKeywords = row["MetaKeywords"].ToString(); indexItem.CreatedUtc = Convert.ToDateTime(row["Created"]); indexItem.LastModUtc = Convert.ToDateTime(row["LastModified"]); indexItem.Content = row["Abstract"].ToString() + " " + row["Description"].ToString() + " " + row["MetaDescription"].ToString() + " " + row["MetaKeywords"].ToString(); // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) { log.Debug("Indexed " + indexItem.Title); } } } catch { } }
private static void IndexItem(Product product) { if (WebConfigSettings.DisableSearchIndex) { return; } if (product == null) { if (log.IsErrorEnabled) { log.Error("product object passed to ProductSearchIndexBuilder.IndexItem was null"); } return; } Store store = new Store(product.StoreGuid); Module module = new Module(store.ModuleId); Guid webStoreFeatureGuid = new Guid("0cefbf18-56de-11dc-8f36-bac755d89593"); ModuleDefinition webStoreFeature = new ModuleDefinition(webStoreFeatureGuid); //// get list of pages where this module is published List<PageModule> pageModules = PageModule.GetPageModulesByModule(store.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( product.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); if (product.SearchIndexPath.Length > 0) { indexItem.IndexPath = product.SearchIndexPath; } indexItem.SiteId = product.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; if (product.Url.Length > 0) { indexItem.ViewPage = product.Url.Replace("~/", string.Empty); indexItem.UseQueryStringParams = false; } else { indexItem.ViewPage = "/WebStore/ProductDetail.aspx"; } indexItem.ItemKey = product.Guid.ToString(); indexItem.ModuleId = store.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = product.Name; indexItem.PageMetaDescription = product.MetaDescription; indexItem.PageMetaKeywords = product.MetaKeywords; indexItem.CreatedUtc = product.Created; indexItem.LastModUtc = product.LastModified; indexItem.Content = product.Teaser + " " + product.Description.Replace(tabScript, string.Empty) + " " + product.MetaDescription + " " + product.MetaKeywords; indexItem.FeatureId = webStoreFeatureGuid.ToString(); indexItem.FeatureName = webStoreFeature.FeatureName; indexItem.FeatureResourceFile = webStoreFeature.ResourceFile; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); } if (debugLog) log.Debug("Indexed " + product.Name); }
private static void IndexItem(ForumThread forumThread) { if (WebConfigSettings.DisableSearchIndex) { return; } if (forumThread == null) { if (log.IsErrorEnabled) { log.Error("forumThread object passed in ForumThreadIndexBuilderProvider.IndexItem was null"); } return; } Forum forum = new Forum(forumThread.ForumId); Module module = new Module(forum.ModuleId); Guid forumFeatureGuid = new Guid("38aa5a84-9f5c-42eb-8f4c-105983d419fb"); ModuleDefinition forumFeature = new ModuleDefinition(forumFeatureGuid); // get list of pages where this module is published List<PageModule> pageModules = PageModule.GetPageModulesByModule(forum.ModuleId); // must update index for all pages containing // this module foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( forumThread.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); if (forumThread.SearchIndexPath.Length > 0) { indexItem.IndexPath = forumThread.SearchIndexPath; } indexItem.SiteId = forumThread.SiteId; indexItem.PageId = pageModule.PageId; indexItem.PageName = pageSettings.PageName; // permissions are kept in sync in search index // so that results are filtered by role correctly indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; indexItem.ItemId = forumThread.ForumId; indexItem.ModuleId = forum.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.FeatureId = forumFeatureGuid.ToString(); indexItem.FeatureName = forumFeature.FeatureName; indexItem.FeatureResourceFile = forumFeature.ResourceFile; indexItem.Title = forumThread.Subject; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; indexItem.ViewPage = "Forums/Thread.aspx"; indexItem.CreatedUtc = forumThread.ThreadDate; indexItem.LastModUtc = forumThread.MostRecentPostDate; if (ForumConfiguration.AggregateSearchIndexPerThread) { indexItem.PublishBeginDate = forumThread.MostRecentPostDate; StringBuilder threadContent = new StringBuilder(); DataTable threadPosts = ForumThread.GetPostsByThread(forumThread.ThreadId); foreach (DataRow r in threadPosts.Rows) { threadContent.Append(r["Post"].ToString()); } //aggregate contents of posts into one indexable content item indexItem.Content = threadContent.ToString(); if (ForumConfiguration.CombineUrlParams) { indexItem.ViewPage = "Forums/Thread.aspx?pageid=" + pageModule.PageId.ToInvariantString() + "&t=" + forumThread.ThreadId.ToInvariantString() + "~1"; indexItem.UseQueryStringParams = false; } indexItem.QueryStringAddendum = "&thread=" + forumThread.ThreadId.ToInvariantString(); } else { //older implementation indexItem.Content = forumThread.PostMessage; indexItem.QueryStringAddendum = "&thread=" + forumThread.ThreadId.ToString() + "&postid=" + forumThread.PostId.ToString(); } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); if (debugLog) { log.Debug("Indexed " + forumThread.Subject); } } }
private static void IndexItem(CalendarEvent calendarEvent) { if (WebConfigSettings.DisableSearchIndex) { return; } if (calendarEvent == null) return; try { //SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); //if ((siteSettings == null) // || (calendarEvent == null)) //{ // return; //} Module module = new Module(calendarEvent.ModuleId); Guid calendarFeatureGuid = new Guid("c5e6a5df-ac2a-43d3-bb7f-9739bc47194e"); ModuleDefinition calendarFeature = new ModuleDefinition(calendarFeatureGuid); // get list of pages where this module is published List<PageModule> pageModules = PageModule.GetPageModulesByModule(calendarEvent.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( calendarEvent.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); if (calendarEvent.SearchIndexPath.Length > 0) { indexItem.IndexPath = calendarEvent.SearchIndexPath; } indexItem.SiteId = calendarEvent.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; indexItem.ItemId = calendarEvent.ItemId; indexItem.ModuleId = calendarEvent.ModuleId; indexItem.ViewPage = "EventCalendar/EventDetails.aspx"; indexItem.FeatureId = calendarFeatureGuid.ToString(); indexItem.FeatureName = calendarFeature.FeatureName; indexItem.FeatureResourceFile = calendarFeature.ResourceFile; indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = calendarEvent.Title; indexItem.Content = calendarEvent.Description; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; indexItem.CreatedUtc = calendarEvent.CreatedDate; indexItem.LastModUtc = calendarEvent.LastModUtc; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); } if (debugLog) log.Debug("Indexed " + calendarEvent.Title); } catch (System.Data.Common.DbException ex) { log.Error("CalendarEventIndexBuilderProvider.IndexItem", ex); } }
public static void RemoveForumIndexItem( int moduleId, int itemId, int threadId, int postId) { if (WebConfigSettings.DisableSearchIndex) { return; } SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { log.Error("siteSettings object retrieved in ForumThreadIndexBuilderProvider.RemoveForumIndexItem was null"); return; } // get list of pages where this module is published List<PageModule> pageModules = PageModule.GetPageModulesByModule(moduleId); // must update index for all pages containing // this module foreach (PageModule pageModule in pageModules) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); // note we are just assigning the properties // needed to derive the key so it can be found and // deleted from the index indexItem.SiteId = siteSettings.SiteId; indexItem.PageId = pageModule.PageId; indexItem.ModuleId = moduleId; indexItem.ItemId = itemId; if ((ForumConfiguration.AggregateSearchIndexPerThread)||(postId == -1)) { indexItem.QueryStringAddendum = "&thread=" + threadId.ToInvariantString(); } else { indexItem.QueryStringAddendum = "&thread=" + threadId.ToInvariantString() + "&postid=" + postId.ToInvariantString(); } mojoPortal.SearchIndex.IndexHelper.RemoveIndex(indexItem); } if (debugLog) log.Debug("Removed Index "); }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if (pageSettings == null) { log.Error("pageSettings object passed to BlogIndexBuilderProvider.RebuildIndex was null"); return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("BlogIndexBuilderProvider indexing page - " + pageSettings.PageName); //try //{ Guid blogFeatureGuid = new Guid("026cbead-2b80-4491-906d-b83e37179ccf"); ModuleDefinition blogFeature = new ModuleDefinition(blogFeatureGuid); List<PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); DataTable dataTable = Blog.GetBlogsByPage( pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { bool includeInSearch = Convert.ToBoolean(row["IncludeInSearch"], CultureInfo.InvariantCulture); if (!includeInSearch) { continue; } DateTime postEndDate = DateTime.MaxValue; if(row["EndDate"] != DBNull.Value) { postEndDate = Convert.ToDateTime(row["EndDate"]); if (postEndDate < DateTime.UtcNow) { continue; } } bool excludeFromRecentContent = Convert.ToBoolean(row["ExcludeFromRecentContent"], CultureInfo.InvariantCulture); mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.ExcludeFromRecentContent = excludeFromRecentContent; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.FeatureId = blogFeatureGuid.ToString(); indexItem.FeatureName = blogFeature.FeatureName; indexItem.FeatureResourceFile = blogFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"], CultureInfo.InvariantCulture); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"], CultureInfo.InvariantCulture); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Heading"].ToString(); string authorName = row["Name"].ToString(); string authorFirstName = row["FirstName"].ToString(); string authorLastName = row["LastName"].ToString(); if ((authorFirstName.Length > 0) && (authorLastName.Length > 0)) { indexItem.Author = string.Format(CultureInfo.InvariantCulture, BlogResources.FirstLastFormat, authorFirstName, authorLastName); } else { indexItem.Author = authorName; } if ((!WebConfigSettings.UseUrlReWriting) || (!BlogConfiguration.UseFriendlyUrls(indexItem.ModuleId))) { indexItem.ViewPage = "Blog/ViewPost.aspx?pageid=" + indexItem.PageId.ToInvariantString() + "&mid=" + indexItem.ModuleId.ToInvariantString() + "&ItemID=" + indexItem.ItemId.ToInvariantString() ; } else { indexItem.ViewPage = row["ItemUrl"].ToString().Replace("~/", string.Empty); } indexItem.PageMetaDescription = row["MetaDescription"].ToString(); indexItem.PageMetaKeywords = row["MetaKeywords"].ToString(); DateTime blogStart = Convert.ToDateTime(row["StartDate"]); indexItem.CreatedUtc = blogStart; indexItem.LastModUtc = Convert.ToDateTime(row["LastModUtc"]); //if (indexItem.ViewPage.Length > 0) //{ indexItem.UseQueryStringParams = false; //} //else //{ // indexItem.ViewPage = "Blog/ViewPost.aspx"; //} indexItem.Content = row["Description"].ToString(); indexItem.ContentAbstract = row["Abstract"].ToString(); int commentCount = Convert.ToInt32(row["CommentCount"]); if (commentCount > 0) { // index comments StringBuilder stringBuilder = new StringBuilder(); DataTable comments = Blog.GetBlogCommentsTable(indexItem.ModuleId, indexItem.ItemId); foreach (DataRow commentRow in comments.Rows) { stringBuilder.Append(" " + commentRow["Comment"].ToString()); stringBuilder.Append(" " + commentRow["Name"].ToString()); if (debugLog) log.Debug("BlogIndexBuilderProvider.RebuildIndex add comment "); } indexItem.OtherContent = stringBuilder.ToString(); } // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } if (blogStart > indexItem.PublishBeginDate) { indexItem.PublishBeginDate = blogStart; } if (postEndDate < indexItem.PublishEndDate) { indexItem.PublishEndDate = postEndDate; } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) log.Debug("Indexed " + indexItem.Title); } //} //catch (Exception ex) //{ // log.Error(ex); //} }
/// <summary> /// This method is called when the site index is rebuilt /// </summary> /// <param name="pageSettings"></param> /// <param name="indexPath"></param> public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if (pageSettings == null) { log.Error("pageSettings object passed to ProductSearchIndexBuilder.RebuildIndex was null"); return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("ProductSearchIndexBuilder indexing page - " + pageSettings.PageName); Guid webStoreFeatureGuid = new Guid("0cefbf18-56de-11dc-8f36-bac755d89593"); ModuleDefinition webStoreFeature = new ModuleDefinition(webStoreFeatureGuid); List<PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); // adding a try catch here because this is invoked even for non-implemented db platforms and it causes an error try { DataTable dataTable = Product.GetBySitePage( pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.FeatureId = webStoreFeatureGuid.ToString(); indexItem.FeatureName = webStoreFeature.FeatureName; indexItem.FeatureResourceFile = webStoreFeature.ResourceFile; indexItem.ItemKey = row["Guid"].ToString(); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"], CultureInfo.InvariantCulture); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Name"].ToString(); indexItem.ViewPage = row["Url"].ToString().Replace("/", string.Empty); if (indexItem.ViewPage.Length > 0) { indexItem.UseQueryStringParams = false; } else { indexItem.ViewPage = "WebStore/ProductDetail.aspx"; } indexItem.PageMetaDescription = row["MetaDescription"].ToString(); indexItem.PageMetaKeywords = row["MetaKeywords"].ToString(); indexItem.CreatedUtc = Convert.ToDateTime(row["Created"]); indexItem.LastModUtc = Convert.ToDateTime(row["LastModified"]); indexItem.Content = row["Abstract"].ToString() + " " + row["Description"].ToString() + " " + row["MetaDescription"].ToString() + " " + row["MetaKeywords"].ToString(); // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) log.Debug("Indexed " + indexItem.Title); } } catch { } }
private static void IndexItem(Link link) { if (WebConfigSettings.DisableSearchIndex) { return; } SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { if (log.IsErrorEnabled) { log.Error("Link object passed to Links.IndexItem was null"); } return; } if (link == null) return; Guid linksFeatureGuid = new Guid("74bdbcc2-0e79-47ff-bcd4-a159270bf36e"); ModuleDefinition linksFeature = new ModuleDefinition(linksFeatureGuid); Module module = new Module(link.ModuleId); // get list of pages where this module is published List<PageModule> pageModules = PageModule.GetPageModulesByModule(link.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( siteSettings.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = siteSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; indexItem.FeatureId = linksFeatureGuid.ToString(); indexItem.FeatureName = linksFeature.FeatureName; indexItem.FeatureResourceFile = linksFeature.ResourceFile; indexItem.ItemId = link.ItemId; indexItem.ModuleId = link.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = link.Title; indexItem.Content = link.Description; indexItem.CreatedUtc = link.CreatedDate; indexItem.LastModUtc = link.CreatedDate; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); } if (debugLog) log.Debug("Indexed " + link.Title); }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if (pageSettings == null) return; //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("CalendarEventIndexBuilderProvider indexing page - " + pageSettings.PageName); try { Guid calendarFeatureGuid = new Guid("c5e6a5df-ac2a-43d3-bb7f-9739bc47194e"); ModuleDefinition calendarFeature = new ModuleDefinition(calendarFeatureGuid); List<PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); DataTable dataTable = CalendarEvent.GetEventsByPage(pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.PageIndex = pageSettings.PageIndex; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.FeatureId = calendarFeatureGuid.ToString(); indexItem.FeatureName = calendarFeature.FeatureName; indexItem.FeatureResourceFile = calendarFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"], CultureInfo.InvariantCulture); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"], CultureInfo.InvariantCulture); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Title"].ToString(); indexItem.Content = row["Description"].ToString(); indexItem.ViewPage = "EventCalendar/EventDetails.aspx"; indexItem.CreatedUtc = Convert.ToDateTime(row["CreatedDate"]); indexItem.LastModUtc = Convert.ToDateTime(row["LastModUtc"]); // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) log.Debug("Indexed " + indexItem.Title); } } catch (System.Data.Common.DbException ex) { log.Error(ex); } }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if (pageSettings == null) { log.Error("LinksIndexBuilderProvider.RebuildIndex error: pageSettings was null "); return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("LinksIndexBuilderProvider indexing page - " + pageSettings.PageName); try { Guid linksFeatureGuid = new Guid("74bdbcc2-0e79-47ff-bcd4-a159270bf36e"); ModuleDefinition linksFeature = new ModuleDefinition(linksFeatureGuid); List<PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); DataTable dataTable = Link.GetLinksByPage( pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.CreatedUtc = Convert.ToDateTime(row["CreatedDate"]); indexItem.LastModUtc = indexItem.CreatedUtc; if (pageSettings.UseUrl) { if (pageSettings.UrlHasBeenAdjustedForFolderSites) { indexItem.ViewPage = pageSettings.UnmodifiedUrl.Replace("~/", string.Empty); } else { indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty); } indexItem.UseQueryStringParams = false; } indexItem.FeatureId = linksFeatureGuid.ToString(); indexItem.FeatureName = linksFeature.FeatureName; indexItem.FeatureResourceFile = linksFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"], CultureInfo.InvariantCulture); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"], CultureInfo.InvariantCulture); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Title"].ToString(); indexItem.Content = row["Description"].ToString(); // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) log.Debug("Indexed " + indexItem.Title); } } catch (System.Data.Common.DbException ex) { log.Error(ex); } }
public void Remove(IndexItem item) { this.List.Remove(item); }
private static void IndexItem(Blog blog) { if (WebConfigSettings.DisableSearchIndex) { return; } if (blog == null) { if (log.IsErrorEnabled) { log.Error("blog object passed to BlogIndexBuilderProvider.IndexItem was null"); } return; } if (!blog.IncludeInSearch) { return; } Module module = new Module(blog.ModuleId); Guid blogFeatureGuid = new Guid("026cbead-2b80-4491-906d-b83e37179ccf"); ModuleDefinition blogFeature = new ModuleDefinition(blogFeatureGuid); // get comments so they can be indexed too StringBuilder stringBuilder = new StringBuilder(); using (IDataReader comments = Blog.GetBlogComments(blog.ModuleId, blog.ItemId)) { while (comments.Read()) { stringBuilder.Append(" " + comments["Comment"].ToString()); stringBuilder.Append(" " + comments["Name"].ToString()); if (debugLog) { log.Debug("BlogIndexBuilderProvider.IndexItem add comment "); } } } // get list of pages where this module is published List <PageModule> pageModules = PageModule.GetPageModulesByModule(blog.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( blog.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); if (blog.SearchIndexPath.Length > 0) { indexItem.IndexPath = blog.SearchIndexPath; } indexItem.SiteId = blog.SiteId; indexItem.ExcludeFromRecentContent = blog.ExcludeFromRecentContent; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; indexItem.PageMetaDescription = blog.MetaDescription; indexItem.PageMetaKeywords = blog.MetaKeywords; indexItem.ItemId = blog.ItemId; indexItem.ModuleId = blog.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = blog.Title; indexItem.Content = blog.Description + " " + blog.MetaDescription + " " + blog.MetaKeywords; indexItem.ContentAbstract = blog.Excerpt; indexItem.FeatureId = blogFeatureGuid.ToString(); indexItem.FeatureName = blogFeature.FeatureName; indexItem.FeatureResourceFile = blogFeature.ResourceFile; indexItem.OtherContent = stringBuilder.ToString(); indexItem.PublishBeginDate = pageModule.PublishBeginDate; if (blog.StartDate > pageModule.PublishBeginDate) { indexItem.PublishBeginDate = blog.StartDate; } indexItem.PublishEndDate = pageModule.PublishEndDate; if (blog.EndDate < pageModule.PublishEndDate) { indexItem.PublishEndDate = blog.EndDate; } if ((blog.UserFirstName.Length > 0) && (blog.UserLastName.Length > 0)) { indexItem.Author = string.Format(CultureInfo.InvariantCulture, BlogResources.FirstLastFormat, blog.UserFirstName, blog.UserLastName); } else { indexItem.Author = blog.UserName; } indexItem.CreatedUtc = blog.StartDate; indexItem.LastModUtc = blog.LastModUtc; if ((!WebConfigSettings.UseUrlReWriting) || (!BlogConfiguration.UseFriendlyUrls(indexItem.ModuleId))) { indexItem.ViewPage = "Blog/ViewPost.aspx?pageid=" + indexItem.PageId.ToInvariantString() + "&mid=" + indexItem.ModuleId.ToInvariantString() + "&ItemID=" + indexItem.ItemId.ToInvariantString() ; } else { indexItem.ViewPage = blog.ItemUrl.Replace("~/", string.Empty); } indexItem.UseQueryStringParams = false; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); } if (debugLog) { log.Debug("Indexed " + blog.Title); } }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if (pageSettings == null) { log.Error("pageSettings object passed to BlogIndexBuilderProvider.RebuildIndex was null"); return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("BlogIndexBuilderProvider indexing page - " + pageSettings.PageName); //try //{ Guid blogFeatureGuid = new Guid("026cbead-2b80-4491-906d-b83e37179ccf"); ModuleDefinition blogFeature = new ModuleDefinition(blogFeatureGuid); List <PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); DataTable dataTable = Blog.GetBlogsByPage( pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { bool includeInSearch = Convert.ToBoolean(row["IncludeInSearch"], CultureInfo.InvariantCulture); if (!includeInSearch) { continue; } DateTime postEndDate = DateTime.MaxValue; if (row["EndDate"] != DBNull.Value) { postEndDate = Convert.ToDateTime(row["EndDate"]); if (postEndDate < DateTime.UtcNow) { continue; } } bool excludeFromRecentContent = Convert.ToBoolean(row["ExcludeFromRecentContent"], CultureInfo.InvariantCulture); mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.ExcludeFromRecentContent = excludeFromRecentContent; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.FeatureId = blogFeatureGuid.ToString(); indexItem.FeatureName = blogFeature.FeatureName; indexItem.FeatureResourceFile = blogFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"], CultureInfo.InvariantCulture); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"], CultureInfo.InvariantCulture); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Heading"].ToString(); string authorName = row["Name"].ToString(); string authorFirstName = row["FirstName"].ToString(); string authorLastName = row["LastName"].ToString(); if ((authorFirstName.Length > 0) && (authorLastName.Length > 0)) { indexItem.Author = string.Format(CultureInfo.InvariantCulture, BlogResources.FirstLastFormat, authorFirstName, authorLastName); } else { indexItem.Author = authorName; } if ((!WebConfigSettings.UseUrlReWriting) || (!BlogConfiguration.UseFriendlyUrls(indexItem.ModuleId))) { indexItem.ViewPage = "Blog/ViewPost.aspx?pageid=" + indexItem.PageId.ToInvariantString() + "&mid=" + indexItem.ModuleId.ToInvariantString() + "&ItemID=" + indexItem.ItemId.ToInvariantString() ; } else { indexItem.ViewPage = row["ItemUrl"].ToString().Replace("~/", string.Empty); } indexItem.PageMetaDescription = row["MetaDescription"].ToString(); indexItem.PageMetaKeywords = row["MetaKeywords"].ToString(); DateTime blogStart = Convert.ToDateTime(row["StartDate"]); indexItem.CreatedUtc = blogStart; indexItem.LastModUtc = Convert.ToDateTime(row["LastModUtc"]); //if (indexItem.ViewPage.Length > 0) //{ indexItem.UseQueryStringParams = false; //} //else //{ // indexItem.ViewPage = "Blog/ViewPost.aspx"; //} indexItem.Content = row["Description"].ToString(); indexItem.ContentAbstract = row["Abstract"].ToString(); int commentCount = Convert.ToInt32(row["CommentCount"]); if (commentCount > 0) { // index comments StringBuilder stringBuilder = new StringBuilder(); DataTable comments = Blog.GetBlogCommentsTable(indexItem.ModuleId, indexItem.ItemId); foreach (DataRow commentRow in comments.Rows) { stringBuilder.Append(" " + commentRow["Comment"].ToString()); stringBuilder.Append(" " + commentRow["Name"].ToString()); if (debugLog) { log.Debug("BlogIndexBuilderProvider.RebuildIndex add comment "); } } indexItem.OtherContent = stringBuilder.ToString(); } // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } if (blogStart > indexItem.PublishBeginDate) { indexItem.PublishBeginDate = blogStart; } if (postEndDate < indexItem.PublishEndDate) { indexItem.PublishEndDate = postEndDate; } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) { log.Debug("Indexed " + indexItem.Title); } } //} //catch (Exception ex) //{ // log.Error(ex); //} }
private static void IndexItem(GalleryImage galleryImage) { if (WebConfigSettings.DisableSearchIndex) { return; } SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if ((siteSettings == null) || (galleryImage == null)) { return; } Guid galleryFeatureGuid = new Guid("d572f6b4-d0ed-465d-ad60-60433893b401"); ModuleDefinition galleryFeature = new ModuleDefinition(galleryFeatureGuid); Module module = new Module(galleryImage.ModuleId); // get list of pages where this module is published List <PageModule> pageModules = PageModule.GetPageModulesByModule(galleryImage.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( siteSettings.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = siteSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; indexItem.FeatureId = galleryFeatureGuid.ToString(); indexItem.FeatureName = galleryFeature.FeatureName; indexItem.FeatureResourceFile = galleryFeature.ResourceFile; indexItem.CreatedUtc = galleryImage.UploadDate; indexItem.LastModUtc = galleryImage.UploadDate; indexItem.ItemId = galleryImage.ItemId; indexItem.ModuleId = galleryImage.ModuleId; indexItem.QueryStringAddendum = "&ItemID" + galleryImage.ModuleId.ToString() + "=" + galleryImage.ItemId.ToString(); indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = galleryImage.Caption; indexItem.Content = galleryImage.Description; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); if (debugLog) { log.Debug("Indexed " + galleryImage.Caption); } } }
private static void IndexItem(HtmlContent content) { bool disableSearchIndex = ConfigHelper.GetBoolProperty("DisableSearchIndex", false); if (disableSearchIndex) { return; } Module module = new Module(content.ModuleId); Guid htmlFeatureGuid = new Guid("881e4e00-93e4-444c-b7b0-6672fb55de10"); ModuleDefinition htmlFeature = new ModuleDefinition(htmlFeatureGuid); // get list of pages where this module is published List<PageModule> pageModules = PageModule.GetPageModulesByModule(content.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( content.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } IndexItem indexItem = new IndexItem(); if (content.SearchIndexPath.Length > 0) { indexItem.IndexPath = content.SearchIndexPath; } indexItem.SiteId = content.SiteId; indexItem.ExcludeFromRecentContent = content.ExcludeFromRecentContent; indexItem.PageId = pageModule.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; if (pageSettings.UseUrl) { indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty); indexItem.UseQueryStringParams = false; } // generally we should not include the page meta because it can result in duplicate results // one for each instance of html content on the page because they all use the smae page meta. // since page meta should reflect the content of the page it is sufficient to just index the content if ((ConfigurationManager.AppSettings["IndexPageMeta"] != null) && (ConfigurationManager.AppSettings["IndexPageMeta"] == "true")) { indexItem.PageMetaDescription = pageSettings.PageMetaDescription; indexItem.PageMetaKeywords = pageSettings.PageMetaKeyWords; } indexItem.FeatureId = htmlFeatureGuid.ToString(); indexItem.FeatureName = htmlFeature.FeatureName; indexItem.FeatureResourceFile = htmlFeature.ResourceFile; indexItem.ItemId = content.ItemId; indexItem.ModuleId = content.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = content.Title; indexItem.Content = SecurityHelper.RemoveMarkup(content.Body); indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; if ((content.CreatedByFirstName.Length > 0) && (content.CreatedByLastName.Length > 0)) { indexItem.Author = string.Format(CultureInfo.InvariantCulture, Resource.FirstLastFormat, content.CreatedByFirstName, content.CreatedByLastName); } else { indexItem.Author = content.CreatedByName; } indexItem.CreatedUtc = content.CreatedDate; indexItem.LastModUtc = content.LastModUtc; if (!module.IncludeInSearch) { indexItem.RemoveOnly = true; } IndexHelper.RebuildIndex(indexItem); } log.Debug("Indexed " + content.Title); }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if (pageSettings == null) { return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info(Resources.GalleryResources.ImageGalleryFeatureName + " indexing page - " + pageSettings.PageName); try { Guid galleryFeatureGuid = new Guid("d572f6b4-d0ed-465d-ad60-60433893b401"); ModuleDefinition galleryFeature = new ModuleDefinition(galleryFeatureGuid); List <PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); DataTable dataTable = GalleryImage.GetImagesByPage(pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); if (pageSettings.UseUrl) { indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty); indexItem.UseQueryStringParams = false; } indexItem.FeatureId = galleryFeatureGuid.ToString(); indexItem.FeatureName = galleryFeature.FeatureName; indexItem.FeatureResourceFile = galleryFeature.ResourceFile; // TODO: it would be good to check the module settings and if not // in compact mode use the GalleryBrowse.aspx page //indexItem.ViewPage = "GalleryBrowse.aspx"; indexItem.ItemId = Convert.ToInt32(row["ItemID"]); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"]); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Caption"].ToString(); indexItem.Content = row["Description"].ToString(); indexItem.QueryStringAddendum = "&ItemID" + row["ModuleID"].ToString() + "=" + row["ItemID"].ToString(); indexItem.CreatedUtc = Convert.ToDateTime(row["UploadDate"]); indexItem.LastModUtc = indexItem.CreatedUtc; // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) { log.Debug("Indexed " + indexItem.Title); } } } catch (System.Data.Common.DbException ex) { log.Error(ex); } }
public static void RebuildIndex(IndexItem indexItem) { if (WebConfigSettings.DisableSearchIndex) { return; } if (indexItem == null) return; if (indexItem.IndexPath.Length > 0) { RebuildIndex(indexItem, indexItem.IndexPath); return; } else if (indexItem.SiteId > -1) { RebuildIndex(indexItem, GetSearchIndexPath(indexItem.SiteId)); return; } string indexPath = GetSearchIndexPath(indexItem.SiteId); RebuildIndex(indexItem, indexPath); }
private static void IndexItem(ForumThread forumThread) { if (WebConfigSettings.DisableSearchIndex) { return; } if (forumThread == null) { if (log.IsErrorEnabled) { log.Error("forumThread object passed in ForumThreadIndexBuilderProvider.IndexItem was null"); } return; } Forum forum = new Forum(forumThread.ForumId); Module module = new Module(forum.ModuleId); Guid forumFeatureGuid = new Guid("38aa5a84-9f5c-42eb-8f4c-105983d419fb"); ModuleDefinition forumFeature = new ModuleDefinition(forumFeatureGuid); // get list of pages where this module is published List <PageModule> pageModules = PageModule.GetPageModulesByModule(forum.ModuleId); // must update index for all pages containing // this module foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( forumThread.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); if (forumThread.SearchIndexPath.Length > 0) { indexItem.IndexPath = forumThread.SearchIndexPath; } indexItem.SiteId = forumThread.SiteId; indexItem.PageId = pageModule.PageId; indexItem.PageName = pageSettings.PageName; // permissions are kept in sync in search index // so that results are filtered by role correctly indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; indexItem.ItemId = forumThread.ForumId; indexItem.ModuleId = forum.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.FeatureId = forumFeatureGuid.ToString(); indexItem.FeatureName = forumFeature.FeatureName; indexItem.FeatureResourceFile = forumFeature.ResourceFile; indexItem.Title = forumThread.Subject; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; indexItem.ViewPage = "Forums/Thread.aspx"; indexItem.CreatedUtc = forumThread.ThreadDate; indexItem.LastModUtc = forumThread.MostRecentPostDate; if (ForumConfiguration.AggregateSearchIndexPerThread) { indexItem.PublishBeginDate = forumThread.MostRecentPostDate; StringBuilder threadContent = new StringBuilder(); DataTable threadPosts = ForumThread.GetPostsByThread(forumThread.ThreadId); foreach (DataRow r in threadPosts.Rows) { threadContent.Append(r["Post"].ToString()); } //aggregate contents of posts into one indexable content item indexItem.Content = threadContent.ToString(); if (ForumConfiguration.CombineUrlParams) { indexItem.ViewPage = "Forums/Thread.aspx?pageid=" + pageModule.PageId.ToInvariantString() + "&t=" + forumThread.ThreadId.ToInvariantString() + "~1"; indexItem.UseQueryStringParams = false; } indexItem.QueryStringAddendum = "&thread=" + forumThread.ThreadId.ToInvariantString(); } else { //older implementation indexItem.Content = forumThread.PostMessage; indexItem.QueryStringAddendum = "&thread=" + forumThread.ThreadId.ToString() + "&postid=" + forumThread.PostId.ToString(); } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); if (debugLog) { log.Debug("Indexed " + forumThread.Subject); } } }
public static IndexItemCollection Browse( int siteId, Guid featureGuid, DateTime modifiedBeginDate, DateTime modifiedEndDate, int pageNumber, int pageSize, out int totalHits) { totalHits = 0; IndexItemCollection results = new IndexItemCollection(); using (Lucene.Net.Store.Directory searchDirectory = GetDirectory(siteId)) { Filter filter = null; BooleanQuery filterQuery = null; if ((modifiedBeginDate.Date > DateTime.MinValue.Date) || (modifiedEndDate.Date < DateTime.MaxValue.Date)) { filterQuery = new BooleanQuery(); // won't be used to score the results TermRangeQuery lastModifiedDateFilter = new TermRangeQuery( "LastModUtc", modifiedBeginDate.Date.ToString("s"), modifiedEndDate.Date.ToString("s"), true, true); filterQuery.Add(lastModifiedDateFilter, Occur.MUST); } if (featureGuid != Guid.Empty) { if (filterQuery == null) { filterQuery = new BooleanQuery(); } BooleanQuery featureFilter = new BooleanQuery(); featureFilter.Add(new TermQuery(new Term("FeatureId", featureGuid.ToString())), Occur.MUST); filterQuery.Add(featureFilter, Occur.MUST); } if (filterQuery != null) { filter = new QueryWrapperFilter(filterQuery); // filterQuery won't affect result scores } MatchAllDocsQuery matchAllQuery = new MatchAllDocsQuery(); using (IndexSearcher searcher = new IndexSearcher(searchDirectory)) { int maxResults = int.MaxValue; TopDocs hits = searcher.Search(matchAllQuery, filter, maxResults); int startHit = 0; if (pageNumber > 1) { startHit = ((pageNumber - 1) * pageSize); } totalHits = hits.TotalHits; if (startHit > totalHits) { startHit = totalHits; } int end = startHit + pageSize; if (totalHits <= end) { end = totalHits; } int itemsAdded = 0; int itemsToAdd = end; for (int i = startHit; i < itemsToAdd; i++) { Document doc = searcher.Doc(hits.ScoreDocs[i].Doc); IndexItem indexItem = new IndexItem(doc, hits.ScoreDocs[i].Score); results.Add(indexItem); itemsAdded += 1; } results.ItemCount = itemsAdded; results.PageIndex = pageNumber; results.ExecutionTime = DateTime.Now.Ticks; // -0; } // using (IndexReader reader = IndexReader.Open(searchDirectory, false)) // { // totalHits = reader.NumDocs(); // int startHit = 0; // int itemsToAdd = pageSize; // if (pageNumber > 1) // { // startHit = ((pageNumber - 1) * pageSize); // int end = startHit + pageSize; // if (totalHits <= end) // { // end = totalHits; // } // itemsToAdd = end; // } // for (int i = startHit; i < itemsToAdd; i++) // { // Document doc = reader.Document(i); // IndexItem indexItem = new IndexItem(doc, 1); // results.Add(indexItem); // } // } } return results; }
public override void RebuildIndex( PageSettings pageSettings, string indexPath) { if (WebConfigSettings.DisableSearchIndex) { return; } if ((pageSettings == null) || (indexPath == null)) { if (log.IsErrorEnabled) { log.Error("pageSettings object or index path passed to ForumThreadIndexBuilderProvider.RebuildIndex was null"); } return; } //don't index pending/unpublished pages if (pageSettings.IsPending) { return; } log.Info("ForumThreadIndexBuilderProvider indexing page - " + pageSettings.PageName); try { List <PageModule> pageModules = PageModule.GetPageModulesByPage(pageSettings.PageId); Guid forumFeatureGuid = new Guid("38aa5a84-9f5c-42eb-8f4c-105983d419fb"); ModuleDefinition forumFeature = new ModuleDefinition(forumFeatureGuid); // new implementation 2012-05-22: get threads by page, then for each thread concat the posts into one item for indexing // previously were indexing individual posts but this makes multiple results in search results for the same thread if (ForumConfiguration.AggregateSearchIndexPerThread) { DataTable threads = ForumThread.GetThreadsByPage( pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in threads.Rows) { StringBuilder threadContent = new StringBuilder(); int threadId = Convert.ToInt32(row["ThreadID"]); DateTime threadDate = Convert.ToDateTime(row["ThreadDate"]); DataTable threadPosts = ForumThread.GetPostsByThread(threadId); foreach (DataRow r in threadPosts.Rows) { threadContent.Append(r["Post"].ToString()); } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } indexItem.CreatedUtc = threadDate; if (row["MostRecentPostDate"] != DBNull.Value) { indexItem.LastModUtc = Convert.ToDateTime(row["MostRecentPostDate"]); } else { indexItem.LastModUtc = threadDate; } indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.FeatureId = forumFeatureGuid.ToString(); indexItem.FeatureName = forumFeature.FeatureName; indexItem.FeatureResourceFile = forumFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"]); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"]); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Subject"].ToString(); indexItem.Content = threadContent.ToString(); if (ForumConfiguration.CombineUrlParams) { indexItem.ViewPage = "Forums/Thread.aspx?pageid=" + pageSettings.PageId.ToInvariantString() + "&t=" + row["ThreadID"].ToString() + "~1"; indexItem.UseQueryStringParams = false; // still need this since it is aprt of the key indexItem.QueryStringAddendum = "&thread=" + row["ThreadID"].ToString(); } else { indexItem.ViewPage = "Forums/Thread.aspx"; indexItem.QueryStringAddendum = "&thread=" + row["ThreadID"].ToString(); } mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) { log.Debug("Indexed " + indexItem.Title); } } } else { //older implementation indexed posts individually DataTable dataTable = ForumThread.GetPostsByPage( pageSettings.SiteId, pageSettings.PageId); foreach (DataRow row in dataTable.Rows) { mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = row["ViewRoles"].ToString(); indexItem.FeatureId = forumFeatureGuid.ToString(); indexItem.FeatureName = forumFeature.FeatureName; indexItem.FeatureResourceFile = forumFeature.ResourceFile; indexItem.ItemId = Convert.ToInt32(row["ItemID"]); indexItem.ModuleId = Convert.ToInt32(row["ModuleID"]); indexItem.ModuleTitle = row["ModuleTitle"].ToString(); indexItem.Title = row["Subject"].ToString(); indexItem.Content = row["Post"].ToString(); indexItem.ViewPage = "Forums/Thread.aspx"; indexItem.QueryStringAddendum = "&thread=" + row["ThreadID"].ToString() + "&postid=" + row["PostID"].ToString(); // lookup publish dates foreach (PageModule pageModule in pageModules) { if (indexItem.ModuleId == pageModule.ModuleId) { indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; } } //indexItem.PublishBeginDate = Convert.ToDateTime(row["PostDate"]); //indexItem.PublishEndDate = DateTime.MaxValue; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem, indexPath); if (debugLog) { log.Debug("Indexed " + indexItem.Title); } } } } catch (System.Data.Common.DbException ex) { log.Error(ex); } }
public static void RemoveIndexItem( int pageId, int moduleId, string itemKey) { if (WebConfigSettings.DisableSearchIndex) { return; } SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { log.Error("IndexHelper.RemoveIndexItem tried to obtain a SiteSettings object but it came back null"); return; } IndexItem indexItem = new IndexItem(); indexItem.SiteId = siteSettings.SiteId; indexItem.PageId = pageId; indexItem.ModuleId = moduleId; indexItem.ItemKey = itemKey; indexItem.IndexPath = GetSearchIndexPath(siteSettings.SiteId); RemoveIndex(indexItem); if (debugLog) log.Debug("Removed Index "); }
private static void IndexItem(SharedFile sharedFile) { if (WebConfigSettings.DisableSearchIndex) { return; } SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if ( (sharedFile == null) || (siteSettings == null) ) { return; } Guid sharedFilesFeatureGuid = new Guid("dc873d76-5bf2-4ac5-bff7-434a87a3fc8e"); ModuleDefinition sharedFilesFeature = new ModuleDefinition(sharedFilesFeatureGuid); Module module = new Module(sharedFile.ModuleId); // get list of pages where this module is published List<PageModule> pageModules = PageModule.GetPageModulesByModule(sharedFile.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( siteSettings.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem(); indexItem.SiteId = siteSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; indexItem.FeatureId = sharedFilesFeatureGuid.ToString(); indexItem.FeatureName = sharedFilesFeature.FeatureName; indexItem.FeatureResourceFile = sharedFilesFeature.ResourceFile; indexItem.CreatedUtc = sharedFile.UploadDate; indexItem.LastModUtc = sharedFile.UploadDate; indexItem.ItemId = sharedFile.ItemId; indexItem.ModuleId = sharedFile.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = sharedFile.FriendlyName.Replace("_", " ").Replace("-", " ").Replace(".", " ") ; indexItem.Content = sharedFile.Description; indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; // make the search results a download link indexItem.ViewPage = "SharedFiles/Download.aspx?pageid=" + indexItem.PageId.ToInvariantString() + "&fileid=" + indexItem.ItemId.ToInvariantString() + "&mid=" + indexItem.ModuleId.ToInvariantString(); indexItem.UseQueryStringParams = false; mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem); } if (debugLog) log.Debug("Indexed " + sharedFile.FriendlyName); }
public static IndexItemCollection Search( int siteId, bool isAdminContentAdminOrSiteEditor, List<string> userRoles, Guid[] featureGuids, DateTime modifiedBeginDate, DateTime modifiedEndDate, string queryText, bool highlightResults, int highlightedFragmentSize, int pageNumber, int pageSize, int maxClauseCount, out int totalHits, out bool invalidQuery) { invalidQuery = false; totalHits = 0; IndexItemCollection results = new IndexItemCollection(); if (string.IsNullOrEmpty(queryText)) { return results; } using (Lucene.Net.Store.Directory searchDirectory = GetDirectory(siteId)) { if (!IndexReader.IndexExists(searchDirectory)) { return results; } long startTicks = DateTime.Now.Ticks; try { if (maxClauseCount != 1024) { BooleanQuery.MaxClauseCount = maxClauseCount; } // there are different analyzers for different languages // see LuceneSettings.config in the root of the web LuceneSettingsProvider provider = LuceneSettingsManager.Providers[GetSiteProviderName(siteId)]; Analyzer analyzer = provider.GetAnalyzer(); Query searchQuery = MultiFieldQueryParser.Parse( Lucene.Net.Util.Version.LUCENE_30, new string[] { queryText, queryText, queryText, queryText, queryText, queryText.Replace("*", string.Empty) }, new string[] { "Title", "ModuleTitle", "contents", "PageName", "PageMetaDesc", "Keyword" }, analyzer); BooleanQuery filterQuery = new BooleanQuery(); // won't be used to score the results if (!isAdminContentAdminOrSiteEditor) // skip role filters for these users { AddRoleFilters(userRoles, filterQuery); AddModuleRoleFilters(userRoles, filterQuery); } TermRangeQuery beginDateFilter = new TermRangeQuery( "PublishBeginDate", DateTime.MinValue.ToString("s"), DateTime.UtcNow.ToString("s"), true, true); filterQuery.Add(beginDateFilter, Occur.MUST); TermRangeQuery endDateFilter = new TermRangeQuery( "PublishEndDate", DateTime.UtcNow.ToString("s"), DateTime.MaxValue.ToString("s"), true, true); filterQuery.Add(endDateFilter, Occur.MUST); if ((modifiedBeginDate.Date > DateTime.MinValue.Date) || (modifiedEndDate.Date < DateTime.MaxValue.Date)) { TermRangeQuery lastModifiedDateFilter = new TermRangeQuery( "LastModUtc", modifiedBeginDate.Date.ToString("s"), modifiedEndDate.Date.ToString("s"), true, true); filterQuery.Add(lastModifiedDateFilter, Occur.MUST); } //if ((!DisableSearchFeatureFilters) && (featureGuid != Guid.Empty)) //{ // BooleanQuery featureFilter = new BooleanQuery(); // featureFilter.Add(new TermQuery(new Term("FeatureId", featureGuid.ToString())), Occur.MUST); // filterQuery.Add(featureFilter, Occur.MUST); //} if ((featureGuids != null) && (featureGuids.Length > 0)) { BooleanQuery featureFilter = new BooleanQuery(); foreach (Guid featureGuid in featureGuids) { featureFilter.Add(new TermQuery(new Term("FeatureId", featureGuid.ToString())), Occur.SHOULD); } filterQuery.Add(featureFilter, Occur.MUST); } Filter filter = new QueryWrapperFilter(filterQuery); // filterQuery won't affect result scores using (IndexSearcher searcher = new IndexSearcher(searchDirectory)) { //http://stackoverflow.com/questions/9872933/migrating-lucene-hitcollector-2-x-to-collector-3-x //TopScoreDocCollector collector = TopScoreDocCollector.Create(maxResults, true); int maxResults = int.MaxValue; TopDocs hits = searcher.Search(searchQuery, filter, maxResults); int startHit = 0; if (pageNumber > 1) { startHit = ((pageNumber - 1) * pageSize); } totalHits = hits.TotalHits; int end = startHit + pageSize; if (totalHits <= end) { end = totalHits; } int itemsAdded = 0; int itemsToAdd = end; QueryScorer scorer = new QueryScorer(searchQuery); SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class='searchterm'>", "</span>"); Highlighter highlighter = new Highlighter(formatter, scorer); highlighter.TextFragmenter = new SimpleFragmenter(highlightedFragmentSize); for (int i = startHit; i < itemsToAdd; i++) { Document doc = searcher.Doc(hits.ScoreDocs[i].Doc); IndexItem indexItem = new IndexItem(doc, hits.ScoreDocs[i].Score); if (highlightResults) { try { TokenStream stream = analyzer.TokenStream("contents", new StringReader(doc.Get("contents"))); string highlightedResult = highlighter.GetBestFragment(stream, doc.Get("contents")); if (highlightedResult != null) { indexItem.Intro = highlightedResult; } } catch (NullReferenceException) { } } results.Add(indexItem); itemsAdded += 1; } results.ItemCount = itemsAdded; results.PageIndex = pageNumber; results.ExecutionTime = DateTime.Now.Ticks - startTicks; } } catch (ParseException ex) { invalidQuery = true; log.Error("handled error for search terms " + queryText, ex); // these parser exceptions are generally caused by // spambots posting too much junk into the search form // heres an option to automatically ban the ip address HandleSpam(queryText, ex); return results; } catch (BooleanQuery.TooManyClauses ex) { invalidQuery = true; log.Error("handled error for search terms " + queryText, ex); return results; } catch (System.IO.IOException ex) { invalidQuery = true; log.Error("handled error for search terms " + queryText, ex); return results; } return results; } }
private static void IndexItem(HtmlContent content) { bool disableSearchIndex = ConfigHelper.GetBoolProperty("DisableSearchIndex", false); if (disableSearchIndex) { return; } Module module = new Module(content.ModuleId); Guid htmlFeatureGuid = new Guid("881e4e00-93e4-444c-b7b0-6672fb55de10"); ModuleDefinition htmlFeature = new ModuleDefinition(htmlFeatureGuid); // get list of pages where this module is published List <PageModule> pageModules = PageModule.GetPageModulesByModule(content.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( content.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } IndexItem indexItem = new IndexItem(); if (content.SearchIndexPath.Length > 0) { indexItem.IndexPath = content.SearchIndexPath; } indexItem.SiteId = content.SiteId; indexItem.ExcludeFromRecentContent = content.ExcludeFromRecentContent; indexItem.PageId = pageModule.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; if (pageSettings.UseUrl) { indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty); indexItem.UseQueryStringParams = false; } // generally we should not include the page meta because it can result in duplicate results // one for each instance of html content on the page because they all use the smae page meta. // since page meta should reflect the content of the page it is sufficient to just index the content if ((ConfigurationManager.AppSettings["IndexPageMeta"] != null) && (ConfigurationManager.AppSettings["IndexPageMeta"] == "true")) { indexItem.PageMetaDescription = pageSettings.PageMetaDescription; indexItem.PageMetaKeywords = pageSettings.PageMetaKeyWords; } indexItem.FeatureId = htmlFeatureGuid.ToString(); indexItem.FeatureName = htmlFeature.FeatureName; indexItem.FeatureResourceFile = htmlFeature.ResourceFile; indexItem.ItemId = content.ItemId; indexItem.ModuleId = content.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = content.Title; indexItem.Content = SecurityHelper.RemoveMarkup(content.Body); indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; if ((content.CreatedByFirstName.Length > 0) && (content.CreatedByLastName.Length > 0)) { indexItem.Author = string.Format(CultureInfo.InvariantCulture, Resource.FirstLastFormat, content.CreatedByFirstName, content.CreatedByLastName); } else { indexItem.Author = content.CreatedByName; } indexItem.CreatedUtc = content.CreatedDate; indexItem.LastModUtc = content.LastModUtc; if (!module.IncludeInSearch) { indexItem.RemoveOnly = true; } IndexHelper.RebuildIndex(indexItem); } log.Debug("Indexed " + content.Title); }