Insert 'Umbraco Tags' via Gathering Node Data Examine Event

668 views Asked by At

I have an Article Doc Type - Two of the properties are multi-node tree pickers.

When a node of this doc type is saved/published, I want to get the ids from these pickers do a look up in umbraco to get the node names. I then want to use those node names to create 'Umbraco Tags' and add them to the index. (against the node being saved)

Because I have two multi-node tree pickers, I want to save the tags as tag groups.

This is so when I do a custom index search, I only have to search for nodes that are of document type Article.

I have my GatheringNodeData Event set up and working, so just need some advice about how its done.

Is this possible/logical?

1

There are 1 answers

0
Tim On

It's certainly possible! In your GatheringNodeData event, you just need to build up the tags fields and add them to the index. Here's some rough code that should give you an idea on how to do it:

private void OnGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
    {
        // Create searchable path
        if (e.Fields.ContainsKey("tagsField"))
        {
            //get the info that you need here and add it to the string you want to index
        }

        // Extract the filename from media items
        e.Fields.Add("modifiedTags", "YOUR STRING HERE");
    }

You can then search for the tag on your "modifiedTags" field. The only issue that you might run into is if you have a tag that contains another tag. E.g. if you had the tags "My Tag" and "My Tag 2" a search for "My Tag" on the new field would return items tagged with both tags.