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 25 posts 76 karma points
    Feb 15, 2021 @ 14:29
    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 1451 posts 9716 karma points MVP 5x c-trib
    Feb 21, 2021 @ 10:03
    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
    Feb 22, 2021 @ 17:56
    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 1451 posts 9716 karma points MVP 5x c-trib
    Feb 22, 2021 @ 18:59
    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
    Feb 22, 2021 @ 19:40
    Dallas
    0

    That's great. Thanks Marc!

  • 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