public static void ParseSearchDefinition(XmlNode searchNode, Guid fieldDefinitionGuid, Guid siteGuid) { ModuleConfiguration config = new ModuleConfiguration(); if (searchNode != null) { //XmlAttributeCollection attrCollection = node.Attributes; //if (attrCollection["fieldDefinitionGuid"] != null) fieldDefinitionGuid = Guid.Parse(attrCollection["fieldDefinitionGuid"].Value); //if (fieldDefinitionGuid == Guid.Empty) return; bool emptySearchDef = false; bool searchDefExists = true; SearchDef searchDef = SearchDef.GetByFieldDefinition(fieldDefinitionGuid); if (searchDef == null) { searchDefExists = false; emptySearchDef = true; searchDef = new SearchDef(); searchDef.FieldDefinitionGuid = fieldDefinitionGuid; searchDef.SiteGuid = siteGuid; searchDef.FeatureGuid = config.FeatureGuid; } foreach (XmlNode childNode in searchNode) { //need to find a way to clear out the searchdef if needed switch (childNode.Name) { case "Title": searchDef.Title = childNode.InnerText.Trim(); emptySearchDef = false; break; case "Keywords": searchDef.Keywords = childNode.InnerText.Trim(); emptySearchDef = false; break; case "Description": searchDef.Description = childNode.InnerText.Trim(); emptySearchDef = false; break; case "Link": searchDef.Link = childNode.InnerText.Trim(); emptySearchDef = false; break; case "LinkQueryAddendum": searchDef.LinkQueryAddendum = childNode.InnerText.Trim(); emptySearchDef = false; break; } //} } if (searchDefExists && emptySearchDef) { SearchDef.DeleteByFieldDefinition(fieldDefinitionGuid); } else if (!emptySearchDef) { searchDef.Save(); } //if (!emptySearchDef) searchDef.Save(); } }
private IndexItem GetIndexItem(PageSettings pageSettings, int moduleID, Item item) { Module module = new Module(moduleID); log.Debug($"moduleid: {moduleID} for module {module.ModuleTitle}"); ModuleConfiguration config = new ModuleConfiguration(module); if (!config.IncludeInSearch) { return(null); } SuperFlexiDisplaySettings displaySettings = new SuperFlexiDisplaySettings(); ModuleDefinition flexiFeature = new ModuleDefinition(config.FeatureGuid); IndexItem indexItem = new IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.FeatureId = flexiFeature.FeatureGuid.ToString(); indexItem.FeatureName = String.IsNullOrWhiteSpace(config.ModuleFriendlyName) ? module.ModuleTitle : config.ModuleFriendlyName; indexItem.FeatureResourceFile = flexiFeature.ResourceFile; indexItem.ItemId = item.ItemID; indexItem.CreatedUtc = item.CreatedUtc; indexItem.LastModUtc = item.LastModUtc; if (pageSettings.UseUrl) { if (pageSettings.UrlHasBeenAdjustedForFolderSites) { indexItem.ViewPage = pageSettings.UnmodifiedUrl.Replace("~/", string.Empty); } else { indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty); } indexItem.UseQueryStringParams = false; } SearchDef searchDef = SearchDef.GetByFieldDefinition(item.DefinitionGuid); bool hasSearchDef = true; if (searchDef == null) { searchDef = new SearchDef(); hasSearchDef = false; } System.Text.StringBuilder sbTitle = new System.Text.StringBuilder(searchDef.Title); System.Text.StringBuilder sbKeywords = new System.Text.StringBuilder(searchDef.Keywords); System.Text.StringBuilder sbDescription = new System.Text.StringBuilder(searchDef.Description); System.Text.StringBuilder sbLink = new System.Text.StringBuilder(searchDef.Link); System.Text.StringBuilder sbLinkQueryAddendum = new System.Text.StringBuilder(searchDef.LinkQueryAddendum); SiteSettings siteSettings = new SiteSettings(pageSettings.SiteGuid); SuperFlexiHelpers.ReplaceStaticTokens(sbTitle, config, false, displaySettings, module, pageSettings, siteSettings, out sbTitle); SuperFlexiHelpers.ReplaceStaticTokens(sbKeywords, config, false, displaySettings, module, pageSettings, siteSettings, out sbKeywords); SuperFlexiHelpers.ReplaceStaticTokens(sbDescription, config, false, displaySettings, module, pageSettings, siteSettings, out sbDescription); SuperFlexiHelpers.ReplaceStaticTokens(sbLink, config, false, displaySettings, module, pageSettings, siteSettings, out sbLink); SuperFlexiHelpers.ReplaceStaticTokens(sbLinkQueryAddendum, config, false, displaySettings, module, pageSettings, siteSettings, out sbLinkQueryAddendum); var fieldValues = ItemFieldValue.GetItemValues(item.ItemGuid); log.Debug($"SuperFlexi Index: total field value count for ItemGuid ({item.ItemGuid}) is {fieldValues.Count}"); foreach (ItemFieldValue fieldValue in fieldValues) { Field field = new Field(fieldValue.FieldGuid); if (field == null || !field.Searchable) { continue; } if (hasSearchDef) { sbTitle.Replace(field.Token, fieldValue.FieldValue); sbKeywords.Replace(field.Token, fieldValue.FieldValue); sbDescription.Replace(field.Token, fieldValue.FieldValue); sbLink.Replace(field.Token, fieldValue.FieldValue); sbLinkQueryAddendum.Replace(field.Token, fieldValue.FieldValue); } else { sbKeywords.Append(fieldValue.FieldValue); } if (debugLog) { log.DebugFormat("RebuildIndex indexing item [{0} = {1}]", field.Name, fieldValue.FieldValue); } } if (hasSearchDef) { sbTitle.Replace("$_ItemID_$", item.ItemID.ToString()); sbKeywords.Replace("$_ItemID_$", item.ItemID.ToString()); sbDescription.Replace("$_ItemID_$", item.ItemID.ToString()); sbLink.Replace("$_ItemID_$", item.ItemID.ToString()); sbLinkQueryAddendum.Replace("$_ItemID_$", item.ItemID.ToString()); indexItem.Content = sbDescription.ToString(); indexItem.Title = sbTitle.ToString(); if (sbLink.Length > 0) { indexItem.ViewPage = sbLink.ToString(); } if (sbLinkQueryAddendum.Length > 0) { indexItem.QueryStringAddendum = sbLinkQueryAddendum.ToString(); indexItem.UseQueryStringParams = false; } } else { indexItem.ModuleTitle = pageSettings.PageName; indexItem.Title = String.IsNullOrWhiteSpace(config.ModuleFriendlyName) ? module.ModuleTitle : config.ModuleFriendlyName; } indexItem.PageMetaKeywords = sbKeywords.ToString(); indexItem.Categories = sbKeywords.ToString(); return(indexItem); }
private void SetupSearchDefinition(XmlNode node) { if (node != null) { XmlAttributeCollection attrCollection = node.Attributes; if (attrCollection["fieldDefinitionGuid"] != null) { fieldDefinitionGuid = Guid.Parse(attrCollection["fieldDefinitionGuid"].Value); } if (fieldDefinitionGuid == Guid.Empty) { return; } SearchDef searchDef = SearchDef.GetByFieldDefinition(fieldDefinitionGuid); if (searchDef == null) { searchDef = new SearchDef(); searchDef.FieldDefinitionGuid = fieldDefinitionGuid; searchDef.SiteGuid = CacheHelper.GetCurrentSiteSettings().SiteGuid; searchDef.FeatureGuid = FeatureGuid; } bool emptySearchDef = true; foreach (XmlNode childNode in node) { //if (!String.IsNullOrWhiteSpace(childNode.InnerText) || !String.IsNullOrWhiteSpace(childNode.InnerXml)) //{ //need to find a way to clear out the searchdef if needed switch (childNode.Name) { case "Title": searchDef.Title = childNode.InnerText.Trim(); emptySearchDef = false; break; case "Keywords": searchDef.Keywords = childNode.InnerText.Trim(); emptySearchDef = false; break; case "Description": searchDef.Description = childNode.InnerText.Trim(); emptySearchDef = false; break; case "Link": searchDef.Link = childNode.InnerText.Trim(); emptySearchDef = false; break; case "LinkQueryAddendum": searchDef.LinkQueryAddendum = childNode.InnerText.Trim(); emptySearchDef = false; break; } //} } if (!emptySearchDef) { searchDef.Save(); } } }
public override void DeleteContent(int moduleId, Guid moduleGuid) { ItemFieldValue.DeleteByModule(moduleGuid); Item.DeleteByModule(moduleGuid); Module module = new Module(moduleGuid); ModuleConfiguration config = new ModuleConfiguration(module); //having field definitions in the database when the fields aren't used by any module is just clutter. //we'll delete the field definitions from the database when they aren't used but of course we don't touch the actual field definition XML files. bool deleteOrphanFields = ConfigHelper.GetBoolProperty("SuperFlexi:DeleteFieldDefinitionsWhenNotUsed", true); //we didn't implement the delete handler for a year or so after building superflexi so we have a lot of instances in the wild that probably have orphaned items //if we upgrade those to this version, create a module instance, and then delete it, these orphaned items will be removed bool deleteOrphanItems = ConfigHelper.GetBoolProperty("SuperFlexi:DeleteOrphanedItemsWhenDeletingModules", true); //clean up search definitions bool deleteOrphanSearchDefinitions = ConfigHelper.GetBoolProperty("SuperFlexi:DeleteOrphanedSearchDefinitions", true); if (deleteOrphanFields || deleteOrphanItems || deleteOrphanSearchDefinitions) { List <Item> sflexiItems = Item.GetForModule(module.ModuleId); List <Guid> definitionGuids = new List <Guid>(); foreach (Item item in sflexiItems) { //add definitionGuids here b/c we'll need them for all three checks definitionGuids.Add(item.DefinitionGuid); if (deleteOrphanItems) { Module checkModule = new Module(item.ModuleGuid); if (checkModule == null) { ItemFieldValue.DeleteByModule(item.ModuleGuid); Item.DeleteByModule(item.ModuleGuid); } } } if (deleteOrphanFields) { definitionGuids = definitionGuids.Distinct().ToList(); foreach (Guid guid in definitionGuids) { List <Item> definitionItems = Item.GetForDefinition(guid, module.SiteGuid); if (definitionItems.Count == 0) { //delete field definitions when there are no more modules using them Field.DeleteByDefinition(guid); if (deleteOrphanSearchDefinitions) { //delete search definitions when there are no more modules using their definition SearchDef.DeleteByFieldDefinition(guid); } } } } } }