Sort the search results on the member search by a custom field

Former Member
Former Member

Can the search results on the member search page be sorted by an ExtendedAttributes or ProfileFields field?

Parents Reply Children
  • Former Member
    0 Former Member in reply to Patrick M.

    Here's the code for the Plugin that I've written to handle the BeforeBulkIndex event for users. I've copied the DLL to the website's bin folder, and the JobServer folder. Does it look okay? How would I get the event to fire for all the users so that it would update all the users?

    using Telligent.Evolution.Extensibility;
    using Telligent.Evolution.Extensibility.Api.Entities.Version1;
    using Telligent.Evolution.Extensibility.Api.Version1;
    
    namespace UserData
    {
        public class UserDataPlugin : Telligent.Evolution.Extensibility.Version1.IPlugin
        {
            public string Name
            {
                get { return "UserDataPlugin"; }
            }
    
            public string Description
            {
                get { return "User Data Plugin"; }
            }
    
    
            public void Initialize()
            {
                Apis.Get<ISearchIndexing>().Events.BeforeBulkIndex += new BeforeSearchBulkIndexingEventHandler(UpdateSortOrder_BeforeBulkIndex);
            }
    
            private void UpdateSortOrder_BeforeBulkIndex(BeforeBulkIndexingEventArgs e)
            {
                UsersGetOptions o = new UsersGetOptions();
                var i = Apis.Get<IUsers>();
                foreach (SearchIndexDocument d in e.Documents)
                {
                    o.ContentId = d.ContentId;
                    var u = i.Get(o);
                    if (u != null)
                    {
                        d.AddField("UserSortOrder", u.ExtendedAttributes["SortOrder"].Value);
                    }
                }
            }
        }
    }

    Here's where I change the sort order in search.vm. Is this correct?

    #set ($searchListOptions = "%{ Query = $searchQuery, Sort = 'UserSortOrder', PageIndex = $pageIndex, PageSize = $pageSize }")

  • In 11.1+, you can go to Administration > Site > Search, view the Include tab, uncheck "Users", Save, recheck "Users", and Save again. This will reindex users.

  • Former Member
    0 Former Member in reply to Ben Tiedt

    Thanks ALL: This is working now. However, I'd like to take it one step further -

    How can I sort the user search results by two fields?

    Also, how can I exclude some users from being included in the index?

  • How can I sort the user search results by two fields?

    The sort can be specified as "FIELD DIRECTION,FIELD DIRECTION,...' where FIELD is the name of the field to sort on and DIRECTION is 'asc' or 'desc'

    Also, how can I exclude some users from being included in the index?

    Users can be excluded by disabling the user's "include in search" option in their settings.