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); } }