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?
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?!
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?!
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?
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.
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
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)
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
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?!
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
I currently have this code and it gets to the bit where it adds "disableBalanceAlert" to ValueSet (currently just defaulting to zero for all).
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?!
I changed
to
and it works.
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
I did find a fix for Umbraco 10 for anyone else.
is working on a reply...