Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mlord 2 posts 82 karma points
    Dec 05, 2022 @ 11:41
    Mlord
    0

    New index or modify existing?

    Hi I'm right now using the standard externalIndex and it works pretty aye okay content-wise. BUT, I've come to a point where I want one of the fields to be indexed differently.

    The field in question contains node id's whereas I want it to contain node names so I can easily search in it.

    I'm having problems finding resources/documentation/guides how I can modify the field in externalIndex.

    Would it instead be better to create a new content index where I seem to be able to adjust the fields more easily? Or any suggestions how to modify the existing index?

    (Umbraco 11)

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Dec 05, 2022 @ 13:56
    Huw Reddick
    1

    https://docs.umbraco.com/umbraco-cms/reference/searching/examine/indexing

    We always recommend that you use the existing built in ExternalIndex. You should then query based on the NodeTypeAlias instead of creating a new separate index based on that particular node type. However, should the need arise, the example below will show you how to do it. Take a look at our Examine Quick Start to see some examples of how to search the ExternalIndex.

  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Dec 05, 2022 @ 15:02
    Bjarne Fyrstenborg
    100

    Here is a typical example from Vendr demostore where one wants to index node data from picked nodes. https://github.com/vendrhub/vendr-demo-store/blob/v3/dev/src/Vendr.DemoStore/Events/TransformExamineValues.cs#L44-L73

    For example having a property with alias categories using a picker datatype (Content Picker, MNTP):

    if (e.ValueSet.Values.ContainsKey("categories"))
    {
        // Prepare a new collection for category names
        var categoryNames = new List<string>();
    
        // Parse the comma separated list of category UDIs
        var categoryIds = e.ValueSet.GetValue("categories").ToString().Split(',')
            .Select(x => UdiParser.TryParse<GuidUdi>(x, out var id) ? id : null)
            .Where(x => x != null)
            .ToList();
    
        // Fetch the category nodes and extract the category name, adding it to the names collection
        using (var ctx = _umbracoContextFactory.EnsureUmbracoContext())
        {
            foreach (var categoryId in categoryIds)
            {
                var category = ctx.UmbracoContext.Content.GetById(categoryId);
                if (category != null)
                {
                    categoryNames.Add(category.Name);
                }
            }
        }
    
        // If we have some names, add these to the lucene index in a searchable way
        if (categoryNames.Count > 0)
        {
            values.Add("categoryNames", new[] { string.Join(" ", categoryNames) });
        }
    }
    
  • Mlord 2 posts 82 karma points
    Dec 05, 2022 @ 16:26
    Mlord
    0

    Thanks both of you. This worked perfectly!

Please Sign in or register to post replies

Write your reply to:

Draft