Skip to content

Instantly share code, notes, and snippets.

@Matthew-Wise
Created July 6, 2018 13:46
Show Gist options
  • Save Matthew-Wise/b685074975c5e0c6cfb1c0e409f3a3d4 to your computer and use it in GitHub Desktop.
Save Matthew-Wise/b685074975c5e0c6cfb1c0e409f3a3d4 to your computer and use it in GitHub Desktop.
Umbraco Multinode picker2 UDI's to GUID for examine
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