Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

This may be a simple question but I am having a hard time figure out how to add Last Name on Sort by in People search.

enter image description here

Any help is greatly appreciated.

Thank you for reading.

//Update - tried to follow suggested instructions but I am not able to modify the xsl

enter image description here

Tried to edit "people Search Core Results" web part and that is showing xsl editor/code however, I can't find the tag.

<xsl:for-each select=”$results”>

Any help is greatly appreciated.

share|improve this question
    
Modifying xslt you can sort only displayed result set (say first 30), but not whole bunch of data. To sort all the data you need to write custom code... Is it acceptable for you? –  Kai Feb 8 '13 at 12:32
    
@Kai I dont mind writing code. Could you possibly point me in the right direction? Thanks! –  user7400 Feb 13 '13 at 20:13

3 Answers 3

In order to display search results using custom sorting order the following Search Results customization should be applied:

Note: The customization described below are verified with People Search Core Results web part.

Important: But before we proceed let me clarify the main limitation of this approach: solution described below allows to sort search results returned not for all results but for results returned for current page only.


Configure Managed Property

In order to LastName to be used in search results it should be configured first. For more details please see Manage metadata properties for search (SharePoint Server 2010)

Steps:

  1. In Central Administration, in the Application Management section, click Manage service applications
  2. Click the Search service application
  3. On the Search Administration page, in the Quick Launch, under Queries and Results, click Metadata Properties. Mapped properties appear.
  4. Find property with name LastName (OOTB LastName property from User Profile is used here) and click on link item.
  5. Make sure that settings for LastName property has the following options enabled (see picture below):

    • Allow this property to be used in scopes
    • Add managed property to custom results set retrieved on each query

    enter image description here

  6. After saving changes for metadata property go to Content Sources
  7. Find Content Source for My Site and start Full Crawl and wait until it will be completed (for details about deploying people search follow here). In my case it is separate Data Source for My Sites hosted on Site Collection (see screenshot below) enter image description here

Configure People Search Core Results web part

In order results to be sorted by LastName property the following properties for People Search Core Results should be modified:

  • Fetched Properties
  • XSL

Steps:

  1. Open the People search results web part in edit mode

  2. Under Location Properties -> Display Properties uncheck Use Local Visualization

  3. Add LastName property to Fetched properties: <Column Name="LastName"/> (Here you could find value for Fetched properties with custom property LastName specified)
  4. Click on XSL editor and add in text the following line <xsl:sort data-type="text" order="ascending" select="lastname"/> after line <xsl:for-each select="All_Results/Result"> For more details about XSL sort see here (Here you could find full XSL for this example)

Results

After these changes you should be able to see people search results sorted by custom property (LastName in our case)
Search result page with results sorted by LastName in ascending order is shown below

enter image description here

For more details about Xslt based approach for sorting search results please follow my post Customizing Search Results (SharePoint 2010): People Search Results Custom Sorting using XSLT


Alternative solutions

If limitations of previous solution is not an options for you, then I suggest you to implement custom web part with custom sorting options.

I also strongly suggest you to implement custom People Core Results web part by deriving it from CoreResultsWebPart class and not implement it from from scratch.

Note: Custom People Core Results web part could not be derived directly from PeopleCoreResultsWebPart because it is marked as Sealed class.

For example, below is presented code, where two public properties OrderByProperty and SortDirection allows to define sorting options:

[ToolboxItemAttribute(false)]
public class SortablePeopleCoreResultsWebPart : CoreResultsWebPart
{

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    [WebDescription("Sort by this managed property")]
    public string OrderByProperty { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    [WebDescription("Sort direction")]
    public Microsoft.Office.Server.Search.Query.SortDirection SortDirection { get; set; }

    /// <summary>
    /// Override. First runs the base code, than collects the CoreResultsDatasource and
    /// sets the SortOrder property.
    /// </summary>
    protected override void ConfigureDataSourceProperties()
    {
        // only do stuff when search results are visible
        if (this.ShowSearchResults)
        {
            // run the base code
            base.ConfigureDataSourceProperties();

            try
            {
                // if OrderByProperty is not set, use default behaviour
                if (!string.IsNullOrEmpty(OrderByProperty))
                {
                    // get the datasource and change the sortorder
                    CoreResultsDatasource dataSource = this.DataSource as CoreResultsDatasource;
                    dataSource.SortOrder.Clear();
                    dataSource.SortOrder.Add(OrderByProperty, SortDirection);
                }
            }
            catch (Exception)
            {
                // handle this error! and show a friendly error message
            }
        }
    }
}
share|improve this answer
2  
Note, that the resulting sort will be applied to results on the page only, it means that search retrieved all results based on rank (by default), then take first 30 (if this is a first page), and then xslt will sort this 30 result on the page. So it is not actual result sort. If you click on second page you can see people with last name starting with letter "A" and so on.. To implement a "actual" sort by last name you have to write custom code. –  Kai Feb 13 '13 at 9:24
    
Well, for some reason my people search results page errors out with an exception once I change the properties of the LastName Metadata field. There is no going past this. Should I need to configure anything else to ensure the people search page stays intact and doesnt error out on me? Thanks! –  user7400 Feb 13 '13 at 14:33
    
@vgrem I dont mind writing code to get this done. Could you possibly point me to a resource I could use to get started? Thanks again! –  user7400 Feb 13 '13 at 16:06
    
@Kai, that's correct, Answer has been updated to make it clear that this the limitation of this approach. Thank you for pointing on this. –  Vadim Gremyachev Feb 13 '13 at 22:37
    
@user7400, the answer has been updated with additional information about alternate solution. –  Vadim Gremyachev Feb 13 '13 at 22:39

Source: http://englando.wordpress.com/2011/01/07/tip-change-sort-order-in-people-matches-sharepoint-2010-web-part/

The People Matches web part in SharePoint 2010 defaults to a sort order that you may not find intuitive. So in order to change it to something more user friendly you will need to edit the web part and modify the XSL.

  • Edit the People Matches web part
  • Expand Display Properties
  • Click on the XSL Editor button
  • I would recommend you select all of the text and paste into Notepad etc as a backup
  • Locate the section that starts <xsl:template match=”/”>
  • Below the line that reads <xsl:for-each select=”$results”> add the following line …

    <xsl:sort data-type=”text” order=”ascending” select=”preferredname”/>

  • You can change the sort field (preferredname) for another should you so desire – dont forget to change the data type if the field you choose is not text

  • Save the XSL and apply the changes
  • When you now do a search and see the results page that includes the People Matches web part you should see people showing in the order you have set

Here's another link I found useful: http://www.mysharepointadventures.com/2011/08/sharepoint-2010-search-results-customisation/

share|improve this answer
1  
Thank you for your reply. This for sure is getting me closer to the answer. However, I was not able to find the tag: <xsl:for-each select=”$results”> Any ideas? –  MicroSumol Jan 4 '13 at 19:30
    
Are you looking at the people matches "results" webpart? Not the search bar webpart –  Mike Jan 4 '13 at 21:23
    
@Mike I got the exact same requirement and cant seem to find $results anywhere on the template. I am looking at "People Search Core Results" webpart. Am I missing anything? –  user7400 Feb 7 '13 at 21:35

Could this be the answer you're looking for?

http://blogs.msdn.com/b/jorman/archive/2010/10/06/custom-search-web-parts-in-2010.aspx

share|improve this answer
    
Yes, that is what I am looking for. However, all it shows is the modified code. Any resources on explaining the entire process of implementing the web part? Thanks! –  user7400 Feb 14 '13 at 13:05
    
I'm not sure what further information you need -> You mentioned a few times that you don't mind writing code. The link shows you how to create a webpart that inherits from the CoreResultsWebPart. Once you have built/compiled/deployed that webpart, you'll be able to use it on a page. –  Jason Rastovski Feb 14 '13 at 14:42
    
Im assuming all I need to do is to simply open up a web part project in Visual Studio, derive from CoreResultsWebPart and deploy to my site? Any other modifications surrounding this? –  user7400 Feb 14 '13 at 15:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.