public IList <SearchDocument> GetModifiedSearchDocuments(ModuleInfo moduleInfo, DateTime beginDate) { var searchDocuments = new List <SearchDocument>(); var isContentModule = moduleInfo.DesktopModule.ModuleName == "2sxc"; // New Context because PortalSettings.Current is null var zoneId = SexyContent.GetZoneID(moduleInfo.OwnerPortalID); if (!zoneId.HasValue) { return(searchDocuments); } var appId = SexyContent.GetDefaultAppId(zoneId.Value); if (!isContentModule) { // Get AppId from ModuleSettings var appIdString = moduleInfo.ModuleSettings[SexyContent.AppIDString]; if (appIdString == null || !int.TryParse(appIdString.ToString(), out appId)) { return(searchDocuments); } } var sexy = new SexyContent(zoneId.Value, appId, true, moduleInfo.OwnerPortalID); var language = moduleInfo.CultureCode; var template = sexy.GetTemplateForModule(moduleInfo.ModuleID); // This list will hold all EAV entities to be indexed var dataSource = sexy.GetViewDataSource(moduleInfo.ModuleID, false, template); if (template == null) { return(searchDocuments); } var engine = EngineFactory.CreateEngine(template); engine.Init(template, sexy.App, moduleInfo, dataSource, InstancePurposes.IndexingForSearch, sexy); try { engine.CustomizeData(); } catch (Exception e) // Catch errors here, because of references to Request etc. { Exceptions.LogException(new SearchIndexException(moduleInfo, e)); } var searchInfoDictionary = new Dictionary <string, List <ISearchInfo> >(); // Get DNN SearchDocuments from 2Sexy SearchInfos foreach (var stream in dataSource.Out.Where(p => p.Key != "Presentation" && p.Key != "ListPresentation")) { var entities = stream.Value.List.Select(p => p.Value); var searchInfoList = searchInfoDictionary[stream.Key] = new List <ISearchInfo>(); searchInfoList.AddRange(entities.Select(entity => { var searchInfo = new SearchInfo() { Entity = entity, Url = "", Description = "", Body = GetJoinedAttributes(entity, language), Title = entity.Title[language].ToString(), ModifiedTimeUtc = (entity.Modified == DateTime.MinValue ? DateTime.Now.Date.AddHours(DateTime.Now.Hour) : entity.Modified).ToUniversalTime(), UniqueKey = "2sxc-" + moduleInfo.ModuleID + "-" + (entity.EntityGuid != new Guid() ? entity.EntityGuid.ToString() : (stream.Key + "-" + entity.EntityId)), IsActive = true, TabId = moduleInfo.TabID, PortalId = moduleInfo.PortalID }; // Take the newest value (from ContentGroupItem and Entity) if (entity is IHasEditingData) { var contentGroupItemModifiedUtc = ((IHasEditingData)entity).ContentGroupItemModified.ToUniversalTime(); searchInfo.ModifiedTimeUtc = searchInfo.ModifiedTimeUtc > contentGroupItemModifiedUtc ? searchInfo.ModifiedTimeUtc : contentGroupItemModifiedUtc; } return(searchInfo); })); } try { engine.CustomizeSearch(searchInfoDictionary, moduleInfo, beginDate); } catch (Exception e) { Exceptions.LogException(new SearchIndexException(moduleInfo, e)); } foreach (var searchInfoList in searchInfoDictionary) { // Filter by Date - take only SearchDocuments that changed since beginDate var searchDocumentsToAdd = searchInfoList.Value.Where(p => p.ModifiedTimeUtc >= beginDate.ToUniversalTime()).Select(p => (SearchDocument)p); searchDocuments.AddRange(searchDocumentsToAdd); } return(searchDocuments); }
/// <summary> /// Get search info for each dnn module containing 2sxc data /// </summary> /// <param name="moduleInfo"></param> /// <param name="beginDate"></param> /// <returns></returns> public IList <SearchDocument> GetModifiedSearchDocuments(ModuleInfo moduleInfo, DateTime beginDate) { // always log with method, to ensure errors are cought Log.Add(() => $"start search for mod#{moduleInfo.ModuleID}"); var searchDocuments = new List <SearchDocument>(); var isContentModule = moduleInfo.DesktopModule.ModuleName == "2sxc"; // New Context because PortalSettings.Current is null var zoneId = new Environment.DnnEnvironment(Log).ZoneMapper.GetZoneId(moduleInfo.OwnerPortalID); //if (!zoneId.HasValue) // return searchDocuments; int?appId = new ZoneRuntime(zoneId, Log).DefaultAppId; if (!isContentModule) { appId = AppHelpers.GetAppIdFromModule(moduleInfo, zoneId); if (!appId.HasValue) { return(searchDocuments); } } // new 2016-03-27 var mcb = new ModuleContentBlock(moduleInfo, Log); var sexy = mcb.SxcInstance; // old 2016-03-27 var language = moduleInfo.CultureCode; //var contentGroup = sexy.App.ContentGroupManager./*AppContentGroups.*/GetContentGroupForModule(moduleInfo.ModuleID, moduleInfo.TabID); var res = sexy.App.ContentGroupManager.GetContentGroupForModule(moduleInfo.ModuleID, moduleInfo.TabID); var contentGroupGuid = res.Item1; var previewTemplateGuid = res.Item2; var contentGroup = sexy.App.ContentGroupManager.GetContentGroupOrGeneratePreview(contentGroupGuid, previewTemplateGuid); var template = contentGroup.Template; // This list will hold all EAV entities to be indexed // before 2016-02-27 2dm: var dataSource = sexy.GetViewDataSource(moduleInfo.ModuleID, false, template); var dataSource = sexy.Data;// ViewDataSource.ForModule(moduleInfo.ModuleID, false, template, sexy); if (template == null) { return(searchDocuments); } var engine = EngineFactory.CreateEngine(template); engine.Init(template, sexy.App, moduleInfo, dataSource, InstancePurposes.IndexingForSearch, sexy, Log); // see if data customization inside the cshtml works try { engine.CustomizeData(); } catch (Exception e) // Catch errors here, because of references to Request etc. { Exceptions.LogException(new SearchIndexException(moduleInfo, e)); } var searchInfoDictionary = new Dictionary <string, List <ISearchInfo> >(); // Get DNN SearchDocuments from 2Sexy SearchInfos foreach (var stream in dataSource.Out.Where(p => p.Key != AppConstants.Presentation && p.Key != AppConstants.ListPresentation)) { var entities = stream.Value.List.Select(p => p.Value); var searchInfoList = searchInfoDictionary[stream.Key] = new List <ISearchInfo>(); searchInfoList.AddRange(entities.Select(entity => { var searchInfo = new SearchInfo { Entity = entity, Url = "", Description = "", Body = GetJoinedAttributes(entity, language), Title = entity.Title != null && entity.Title[language] != null ? entity.Title[language].ToString() : "(no title)", ModifiedTimeUtc = (entity.Modified == DateTime.MinValue ? DateTime.Now.Date.AddHours(DateTime.Now.Hour) : entity.Modified).ToUniversalTime(), UniqueKey = "2sxc-" + moduleInfo.ModuleID + "-" + (entity.EntityGuid != new Guid() ? entity.EntityGuid.ToString() : (stream.Key + "-" + entity.EntityId)), IsActive = true, TabId = moduleInfo.TabID, PortalId = moduleInfo.PortalID }; // Take the newest value (from ContentGroupItem and Entity) if (entity is IHasEditingData) { var contentGroupItemModifiedUtc = ((IHasEditingData)entity).ContentGroupItemModified.ToUniversalTime(); searchInfo.ModifiedTimeUtc = searchInfo.ModifiedTimeUtc > contentGroupItemModifiedUtc ? searchInfo.ModifiedTimeUtc : contentGroupItemModifiedUtc; } return(searchInfo); })); } // check if the cshtml has search customizations try { engine.CustomizeSearch(searchInfoDictionary, moduleInfo, beginDate); } catch (Exception e) { Exceptions.LogException(new SearchIndexException(moduleInfo, e)); } // reduce load by only keeping recently modified ites foreach (var searchInfoList in searchInfoDictionary) { // Filter by Date - take only SearchDocuments that changed since beginDate var searchDocumentsToAdd = searchInfoList.Value.Where(p => p.ModifiedTimeUtc >= beginDate.ToUniversalTime()).Select(p => (SearchDocument)p); searchDocuments.AddRange(searchDocumentsToAdd); } return(searchDocuments); }
public IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo moduleInfo, DateTime beginDate) { var searchDocuments = new List<SearchDocument>(); var isContentModule = moduleInfo.DesktopModule.ModuleName == "2sxc"; // New Context because PortalSettings.Current is null var zoneId = SexyContent.GetZoneID(moduleInfo.OwnerPortalID); if (!zoneId.HasValue) return searchDocuments; int? appId = SexyContent.GetDefaultAppId(zoneId.Value); if (!isContentModule) { appId = SexyContent.GetAppIdFromModule(moduleInfo); if (!appId.HasValue) return searchDocuments; } var sexy = new SexyContent(zoneId.Value, appId.Value, true, moduleInfo.OwnerPortalID); var language = moduleInfo.CultureCode; var contentGroup = sexy.ContentGroups.GetContentGroupForModule(moduleInfo.ModuleID); var template = contentGroup.Template; // This list will hold all EAV entities to be indexed var dataSource = sexy.GetViewDataSource(moduleInfo.ModuleID, false, template); if (template == null) return searchDocuments; var engine = EngineFactory.CreateEngine(template); engine.Init(template, sexy.App, moduleInfo, dataSource, InstancePurposes.IndexingForSearch, sexy); try { engine.CustomizeData(); } catch (Exception e) // Catch errors here, because of references to Request etc. { Exceptions.LogException(new SearchIndexException(moduleInfo, e)); } var searchInfoDictionary = new Dictionary<string, List<ISearchInfo>>(); // Get DNN SearchDocuments from 2Sexy SearchInfos foreach (var stream in dataSource.Out.Where(p => p.Key != "Presentation" && p.Key != "ListPresentation" )) { var entities = stream.Value.List.Select(p => p.Value); var searchInfoList = searchInfoDictionary[stream.Key] = new List<ISearchInfo>(); searchInfoList.AddRange(entities.Select(entity => { var searchInfo = new SearchInfo { Entity = entity, Url = "", Description = "", Body = GetJoinedAttributes(entity, language), Title = entity.Title != null ? entity.Title[language].ToString() : "(no title)", ModifiedTimeUtc = (entity.Modified == DateTime.MinValue ? DateTime.Now.Date.AddHours(DateTime.Now.Hour) : entity.Modified).ToUniversalTime(), UniqueKey = "2sxc-" + moduleInfo.ModuleID + "-" + (entity.EntityGuid != new Guid() ? entity.EntityGuid.ToString() : (stream.Key + "-" + entity.EntityId)), IsActive = true, TabId = moduleInfo.TabID, PortalId = moduleInfo.PortalID }; // Take the newest value (from ContentGroupItem and Entity) if (entity is IHasEditingData) { var contentGroupItemModifiedUtc = ((IHasEditingData) entity).ContentGroupItemModified.ToUniversalTime(); searchInfo.ModifiedTimeUtc = searchInfo.ModifiedTimeUtc > contentGroupItemModifiedUtc ? searchInfo.ModifiedTimeUtc : contentGroupItemModifiedUtc; } return searchInfo; })); } try { engine.CustomizeSearch(searchInfoDictionary, moduleInfo, beginDate); } catch (Exception e) { Exceptions.LogException(new SearchIndexException(moduleInfo, e)); } foreach (var searchInfoList in searchInfoDictionary) { // Filter by Date - take only SearchDocuments that changed since beginDate var searchDocumentsToAdd = searchInfoList.Value.Where(p => p.ModifiedTimeUtc >= beginDate.ToUniversalTime()).Select(p => (SearchDocument) p); searchDocuments.AddRange(searchDocumentsToAdd); } return searchDocuments; }