Copied to clipboard

Flag this post as spam?

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


  • Kalle Wibeck 24 posts 75 karma points
    1 week ago
    Kalle Wibeck
    0

    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

  • Marc Goodson 1415 posts 9546 karma points MVP 5x c-trib
    6 days ago
    Marc Goodson
    0

    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;

    public class CustomUmbracoTreeSearcherFields : UmbracoTreeSearcherFields,     IUmbracoTreeSearcherFields
    {
        public List<string> GetBackOfficeMembersFields()
        {
            var list = base.GetBackOfficeMembersFields().ToList();
            list.Add("aliasOfCustomField");
            return list;
        }
    }
    

    regards

    Marc

  • Dallas 131 posts 403 karma points
    5 days ago
    Dallas
    0

    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.

    enter image description here

    (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/

  • Marc Goodson 1415 posts 9546 karma points MVP 5x c-trib
    5 days ago
    Marc Goodson
    0

    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

  • Dallas 131 posts 403 karma points
    5 days ago
    Dallas
    0

    That's great. Thanks Marc!

Please Sign in or register to post replies

Write your reply to:

Draft