So if you create the following in a c# class and compile it as part of your Umbraco solution, and recycle the application pool, then Umbraco will discover this code at startup and add your custom field to the ones already searched;
public class CustomUmbracoTreeSearcherFields : UmbracoTreeSearcherFields, IUmbracoTreeSearcherFields
{
public List<string> GetBackOfficeMembersFields()
{
var list = base.GetBackOfficeMembersFields().ToList();
list.Add("aliasOfCustomField");
return list;
}
}
Hi Kalle, Marc - customizing the member search is something that I have been working on too. Our editors need to find members using the custom member properties (in our case, company name and employer id).
I added a CustomUmbracoTreeSearchFields class to the project similar to Marc's example but was not getting any results when searching on the custom member properties.
public class CustomUmbracoTreeSearcherFields : UmbracoTreeSearcherFields, IUmbracoTreeSearcherFields
{
public new IEnumerable<string> GetBackOfficeMembersFields()
{
var list = base.GetBackOfficeMembersFields().ToList();
list.Add("accountNumber");
list.Add("employerName");
return list;
}
}
I dug into the Umbraco source and found that the default UmbracoTreeSearchFields class is loaded with the RegisterUnique() method.
From Stephan's blog post I found that the purpose of RegisterUnique() is to only ever load one instance of the type. I needed to register the custom class in a composer for searching on custom member properties to work.
public class UmbracoTreeSearcherFieldsComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.RegisterUnique<IUmbracoTreeSearcherFields, CustomUmbracoTreeSearcherFields>();
}
}
The other issue I had was that I was using the list search box in the member section to search but this solution applies to the site level search (accessed from the the menu bar). You can search for the members from any section.
(Is it possible to customize the member list search? This would be more useful as the results show more details. In the site search you only see the username and email address in the result list.)
In addition, the indexing needs to be updated to include the custom member properties. By default only username and email are indexed but this can be changed by changing the indexing as described here:
In terms of searching the ListView, this isn't using the Examine Index, it goes straight to the database... however this is a great article here about how you can hijack this request and implement your own backoffice search for a ListView....
Thanks for your suggest, I tried to implement it into an Umbraco installation.
First of all, I changed the "RegisterUnique" with "RegisterUniqueFor" in the Compose method (I'm using Umbraco 8.16.x):
public class UmbracoTreeSearcherFieldsComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.RegisterUniqueFor<IUmbracoTreeSearcherFields, CustomUmbracoTreeSearcherFields>();
}
}
(RegisterUnique is no longer available to use with Service and Target as generics).
The UmbracoTreeSearcherFields now has a constructor with argument, so I changed in:
public class CustomUmbracoTreeSearcherFields : UmbracoTreeSearcherFields, IUmbracoTreeSearcherFields
{
public CustomUmbracoTreeSearcherFields(LocalizationService localizationService) : base(localizationService) { }
public new IEnumerable<string> GetBackOfficeFields()
{
return new List<string>(base.GetBackOfficeFields()) { "myCustomProperty" };
}
}
The CustomUmbracoTreeSearcherFields() constructor changed in later versions and requires the LocalizationService parameter.
Composition.RegisterUnique works but the constructor parameter type needs to be the ILocalizationService Interface for the Dependency Injection to work.
public class UmbracoTreeSearcherFieldsComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.RegisterUnique<IUmbracoTreeSearcherFields, CustomUmbracoTreeSearcherFields>();
}
}
public class CustomUmbracoTreeSearcherFields : UmbracoTreeSearcherFields, IUmbracoTreeSearcherFields
{
public CustomUmbracoTreeSearcherFields(ILocalizationService localizationService) : base(localizationService) { }
public new IEnumerable<string> GetBackOfficeFields()
{
return new List<string>(base.GetBackOfficeFields()) { "myCustomProperty" };
}
}
Search in custom member attributes?
Hi!
Is it possible to somehow search in custom members properties?
Say that I've added a custom property "city" can I somehow make this searchable in the great UGuardian table?
Thanks,
// Kalle
Hi Kalle
By default, the search will only consider the Name and Email fields, however you can extend this to use custom properties by implementing:
https://our.umbraco.com/documentation/Extending/Backoffice-Search/
So if you create the following in a c# class and compile it as part of your Umbraco solution, and recycle the application pool, then Umbraco will discover this code at startup and add your custom field to the ones already searched;
regards
Marc
Hi Kalle, Marc - customizing the member search is something that I have been working on too. Our editors need to find members using the custom member properties (in our case, company name and employer id).
I added a CustomUmbracoTreeSearchFields class to the project similar to Marc's example but was not getting any results when searching on the custom member properties.
I dug into the Umbraco source and found that the default UmbracoTreeSearchFields class is loaded with the RegisterUnique() method.
From Stephan's blog post I found that the purpose of RegisterUnique() is to only ever load one instance of the type. I needed to register the custom class in a composer for searching on custom member properties to work.
The other issue I had was that I was using the list search box in the member section to search but this solution applies to the site level search (accessed from the the menu bar). You can search for the members from any section.
(Is it possible to customize the member list search? This would be more useful as the results show more details. In the site search you only see the username and email address in the result list.)
In addition, the indexing needs to be updated to include the custom member properties. By default only username and email are indexed but this can be changed by changing the indexing as described here:
https://our.umbraco.com/documentation/Reference/Searching/Examine/indexing/
Hi Dallas
Thanks for updating further!
In terms of searching the ListView, this isn't using the Examine Index, it goes straight to the database... however this is a great article here about how you can hijack this request and implement your own backoffice search for a ListView....
https://dev.to/skttl/how-to-customize-searching-in-umbraco-list-views-1knk
regards
Marc
That's great. Thanks Marc!
Thanks for your suggest, I tried to implement it into an Umbraco installation. First of all, I changed the "RegisterUnique" with "RegisterUniqueFor" in the Compose method (I'm using Umbraco 8.16.x):
(RegisterUnique is no longer available to use with Service and Target as generics).
The UmbracoTreeSearcherFields now has a constructor with argument, so I changed in:
But is not working. Any suggestion?
Did you ever find a fix for this?
The CustomUmbracoTreeSearcherFields() constructor changed in later versions and requires the LocalizationService parameter.
Composition.RegisterUnique works but the constructor parameter type needs to be the ILocalizationService Interface for the Dependency Injection to work.
is working on a reply...