Copied to clipboard

Flag this post as spam?

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


  • Gordon Saxby 1461 posts 1883 karma points
    May 16, 2022 @ 12:24
    Gordon Saxby
    0

    Custom fields not in Member Examine Index

    I have added extra properties to the "Member" Member Type.

    I went to MembersIndex in Examine Management and did a search for a member record. The result says there are only 9 fields and the list of fields is just the standard fields - none of the ones I added are there.

    What do I need to do in order to add custom fields to the MemberIndex?

    enter image description here

  • Gordon Saxby 1461 posts 1883 karma points
    May 20, 2022 @ 15:08
    Gordon Saxby
    0

    I've (eventually) found and tried to follow code here https://our.umbraco.com/documentation/Reference/Searching/Examine/indexing/ but it seems to be invalid for Umbraco v9?!

    Any help or clues would be much appreciated.

  • Peter van den Dungen 66 posts 365 karma points
    May 21, 2022 @ 16:23
    Peter van den Dungen
    0

    The v9 docs are behind for this topic , you can't use the v8 code for this.

    Take a look here: https://our.umbraco.com/forum/umbraco-9/107736-v9-search-indexes-how-do-you-update-the-field-definition-type

  • Gordon Saxby 1461 posts 1883 karma points
    May 23, 2022 @ 09:34
    Gordon Saxby
    0

    Thanks for the link but unfortunately it does seem to really help me (or it's not working).

    I want to add additional fields to the Members index. I tried this but it didn't work (didn't add my field to the index)

        public sealed class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
    {
        public void Configure(string name, LuceneDirectoryIndexOptions options)
        {
            switch (name)
            {
                case Constants.UmbracoIndexes.MembersIndexName:
                    options.FieldDefinitions.TryAdd(new FieldDefinition("disableBalanceAlert", FieldDefinitionTypes.Integer));
                    break;
    
                default:
                    break;
            }
        }
    
        public void Configure(LuceneDirectoryIndexOptions options)
            => Configure(string.Empty, options);
    }
    
        public class SearchComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.Services.ConfigureOptions<ConfigureIndexOptions>();
        }
    }
    
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    May 23, 2022 @ 09:54
    Dave Woestenborghs
    0

    Hi Gordon,

    You probably aslo need to hook into the TransformIndexValues event to index the actual values. See https://our.umbraco.com/Documentation/Reference/Searching/Examine/examine-events#transformingindexvalues

    Dave

  • Gordon Saxby 1461 posts 1883 karma points
    May 23, 2022 @ 10:28
    Gordon Saxby
    0

    That seems to be V8 code as well. Also, it seems to allow me to access existing (standard) fields, but the field (or fields) I'm trying to add isn't showing up?

    Oh, and the code on that page seems to be invalid too - "indexProvider" in Terminate() is not defined?!

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    May 23, 2022 @ 14:00
    Dave Woestenborghs
    0

    Hi Gordon.

    The code is for V8, but would be identical in V9. I don't think you need the code in the terminate method.

    Dave

  • Gordon Saxby 1461 posts 1883 karma points
    May 23, 2022 @ 14:37
    Gordon Saxby
    100

    I currently have this code and it gets to the bit where it adds "disableBalanceAlert" to ValueSet (currently just defaulting to zero for all).

        public class SearchComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.Services.ConfigureOptions<ConfigureIndexOptions>();
        }
    }
    
    public sealed class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
    {
        public void Configure(string name, LuceneDirectoryIndexOptions options)
        {
            switch (name)
            {
                case Constants.UmbracoIndexes.MembersIndexName:
                    options.FieldDefinitions.TryAdd(new FieldDefinition("disableBalanceAlert", FieldDefinitionTypes.Integer));
                    break;
    
                default:
                    break;
            }
        }
    
        public void Configure(LuceneDirectoryIndexOptions options)
            => Configure(string.Empty, options);
    }
    
    public class SubscribeToExamineSetupComposer : ComponentComposer<ExamineComponents>
    { }
    
    public class ExamineComponents : IComponent
    {
        private readonly IUmbracoContextFactory _contextFactory;
        private readonly IExamineManager _examineManager;
    
        public ExamineComponents(
            IUmbracoContextFactory contextFactory,
            IExamineManager examineManager
            )
        {
            _contextFactory = contextFactory;
            _examineManager = examineManager;
        }
    
        public void Initialize()
        {
            if (!_examineManager.TryGetIndex(Umbraco.Cms.Core.Constants.UmbracoIndexes.MembersIndexName,
                    out IIndex index))
            {
                throw new InvalidOperationException(
                    $"No index found by the name {Umbraco.Cms.Core.Constants.UmbracoIndexes.MembersIndexName}");
            }
    
            if (!(index is BaseIndexProvider indexProvider))
                throw new InvalidOperationException("Could not cast)");
    
            indexProvider.TransformingIndexValues += IndexProviderTransformingIndexValues;
        }
    
        private void IndexProviderTransformingIndexValues(object? sender, IndexingItemEventArgs e)
        {
            if (int.TryParse(e.ValueSet.Id, out var memberId))
            {
                if (e.ValueSet.ItemType == "Member")
                {
                    e.ValueSet.Add("disableBalanceAlert", "0");
                }
            }
        }
    
        public void Terminate()
        {
        }
    }
    

    However, if I do a search in the Umbraco backend it does not find any records.

    If I just enter a member email address, I get a result. If I enter "disableBalanceAlert = 0" I get nothing. So it looks like I'm still missing something?!

  • Gordon Saxby 1461 posts 1883 karma points
    May 23, 2022 @ 15:29
    Gordon Saxby
    0

    I changed

                    e.ValueSet.Add("disableBalanceAlert", "0");
    

    to

                    e.ValueSet.Add("searchDisableBalanceAlert", "0");
    

    and it works.

  • Dee 118 posts 338 karma points
    Sep 17, 2022 @ 16:34
    Dee
    0

    Hey Gordon,

    are you able to query your members via publishedContentQuery?

    I have this documented issue and am wondering, if anyone knows how to deal with it:

    https://github.com/umbraco/Umbraco-CMS/issues/13001

  • Nick 8 posts 98 karma points
    May 16, 2024 @ 23:49
    Nick
    0

    I did find a fix for Umbraco 10 for anyone else.

    public class InitaliseMemberIndexComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.Services.ConfigureOptions<ConfigureIndexOptions>();
        }
    }
    
    
    public sealed class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
    {
        public void Configure(string name, LuceneDirectoryIndexOptions options)
        {
            List<string> additionalFields = new List<string> { "skills" };
            additionalFields.AddRange(MemberValueSetValidator.DefaultMemberIndexFields);
            switch (name)
            {
                case Umbraco.Cms.Core.Constants.UmbracoIndexes.MembersIndexName:
                    options.Validator = new MemberValueSetValidator(null, null, additionalFields, null);
    
                    break;
    
                default:
                    break;
            }
        }
    
        public void Configure(LuceneDirectoryIndexOptions options)
            => Configure(string.Empty, options);
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft