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
No Data
Reply Children
  • Former Member
    0 Former Member in reply to Patrick M.

    Hi,

    Here's the C# code:

       public class MyUsers
        {
    
            public string GetContentIds()
            {
                SqlDataAccess sd = new SqlDataAccess();
                using (SqlCommand cmd = sd.GetCommand("ibby_Get_Sorted_User_Content_Ids"))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    DataTable dt = sd.Execute(cmd);
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        sb.Append(dt.Rows[i]["ContentId"].ToString());
                        if (i != dt.Rows.Count - 1)
                            sb.Append(",");
                    }
                    return sb.ToString();
                }
            }
    
            public PagedList<Telligent.Evolution.Extensibility.Api.Entities.Version1.User> GetUsers()
            {
                UsersListOptions options = new UsersListOptions();
                options.ContentIds = GetContentIds();
                options.SortBy = "ContentIdsOrder";
                return Apis.Get<Users>().List(options);
            }
    
        }
    

    And search.vm

    #set($filters = $core_v2_page.GetFormValue('filters'))
    
    ## perform search
    #set($count = 0)
    
    #set ($searchListOptions = "%{ Query = $searchQuery, Sort = 'titlesort', PageIndex = $pageIndex, PageSize = $pageSize }")
    $searchListOptions.Add("Filters", "type::user${filters}")
    ##set ($searchResults = $core_v2_searchResult.List($searchListOptions))
    
    #set ($searchResults = $!$ibby_v1_UserData.GetUsers())   
    ## Render Search Results
    
    #set ($hasMore = false)
    #set ($currentPagedQuantity = ($searchResults.PageIndex + 1) * $searchResults.PageSize)
    #if ($searchResults.TotalCount > $currentPagedQuantity)
    	#set ($hasMore = true)
    #end
    
    #foreach ($user in $searchResults)
    #beforeall
    
    	<div class="content-list thumbnail ui-masonry margin-top" id="$core_v2_encoding.HtmlAttributeEncode($core_v2_widget.UniqueId('thumbnails'))" data-columnclass="thumbnail-column">
    #each
    	##set ($user = false)
    	##foreach ($resultUser in $result.Users)
    	##	#set ($user = $resultUser)
    	###end