Copied to clipboard

Flag this post as spam?

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


  • Paul de Quant 394 posts 1477 karma points
    Dec 22, 2015 @ 17:25
    Paul de Quant
    0

    Indexing Custom User fields in Examine

    Hello,

    I need to create a custom user field that I need to be indexed for search (I'm doing a faceted search using Xuntos).

    I've tried creating a custom field using the ExamineEventHandler and the GatheringNodeData function, it all appears to work fine on the surface - however when I rebuild the index I don't see the the new field in the users fields table. But when I search I can see it has been indexed - how to I get my custom field to appear in the list?

    Heres my code:-

    private void ExamineEventHandler_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
    
            if (e.IndexType != UmbracoExamine.IndexTypes.Content)
                return;
    
            var fields = e.Fields;
    
            var tagKey = new StringBuilder();
    
            foreach (var field in fields)
            {
                try
                {
                    if (field.Key == "npt")
                    {
                        if (!string.IsNullOrEmpty(field.Value))
                        {
                            var array = field.Value;
                            List<string> tmp = Regex.Replace(array, "[^0-9a-zA-Z/,]+", "").Split(',').ToList();
                            foreach (var tag in tmp)
                            {
                                tagKey.Append(tag + ",");
                            }
    
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Do nothing
                }
    
            }
    
            // Add field to index
            e.Fields.Add("nptLocations", tagKey.ToString().TrimEnd(','));
        }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies