Created
July 6, 2018 13:46
-
-
Save Matthew-Wise/b685074975c5e0c6cfb1c0e409f3a3d4 to your computer and use it in GitHub Desktop.
Umbraco Multinode picker2 UDI's to GUID for examine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ContentPublishEvents : IApplicationEventHandler | |
{ | |
public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) | |
{ | |
} | |
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) | |
{ | |
} | |
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) | |
{ | |
ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].GatheringNodeData += (sender, e) => ExternalIndexerGatheringNodeData(e); | |
} | |
private static void ExternalIndexerGatheringNodeData(IndexingNodeEventArgs e) | |
{ | |
if (e.IndexType != IndexTypes.Content) return; | |
ConvertUdiToGuidStringField(e, "serviceTags"); | |
ConvertUdiToGuidStringField(e, "sectorTags"); | |
} | |
private static void ConvertUdiToGuidStringField(IndexingNodeEventArgs e, string field) | |
{ | |
if (!e.Fields.ContainsKey(field)) return; | |
var raw = e.Fields[field]; | |
if (string.IsNullOrWhiteSpace(raw)) return; | |
var guids = raw.Replace("umb://document/", " ", StringComparison.InvariantCultureIgnoreCase).Replace(",", string.Empty, StringComparison.InvariantCultureIgnoreCase).Trim(); | |
e.Fields.Add(field + "Guid", string.Join(" ", guids)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment