I have some Taxonomy that I want to modify when a document is being saved/published.
In backoffice it looks like this.
This is how it looks in the index right now for the “tags” field:
[“Udgivelser”,“Sanglege”,“Rytme/puls/bodypercussion”,“Opvarmning/Stemmetræning/Energizere”,“Rekvisitsange/instrumenter”,“Noder”]
And I would like to look like this:
[“Udgivelser”,“Sanglege”,“Rytme”,“puls”,“bodypercussion”,“Opvarmning”,“Stemmetræning”,“Energizere”,“Rekvisitsange”,“instrumenter”,“Noder”]
I know how to use notifications to hook into the saving/publishing so that not the issue and I also have made the split of the original data.
I basically just need to figure out how to update the field in the index.
Can anyone give me a few pointers ?
This is how my code looks for now:
public void Handle(ContentPublishingNotification notification)
{
if (!_examineManager.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out IIndex index))
{
throw new InvalidOperationException($"No index found by name{Constants.UmbracoIndexes.ExternalIndexName}");
}
if (notification.PublishedEntities.Any())
{
foreach (var item in notification.PublishedEntities)
{
var node = _umbracoHelper.Content(item.Id);
if (node != null && node.ContentType.CompositionAliases.Contains("taxonomiPageComposition"))
{
var tags = node.Value<List<string>>("tags") ?? new List<string>();
var splitTags = tags.SelectMany(tag => tag.Split('/', StringSplitOptions.RemoveEmptyEntries)).ToList();
// How do I find the document in the index and update the field named tags ?
}
}
}
}
