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

Like the title says, is there a way to edit the Sort By options for the People Search Results page. Currently the options are 'Default', 'Social Distance', and 'Name'. I'm assuming this is going to require editing, the XSL, but I don't even know what to look for in there. A link to a tutorial would be great.

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Sort Options control is rendered using XSLT for Search Action Links and Core Results for People web parts. So, the preferable way to customize it using XSLT based approach.

Solution

Lets discuss how to provide additional sorting options as shown on picture below

enter image description here

  1. Provide custom sorting options values. ParameterBindings property is used here for storing custom sort options values and passing them to XSLT

    <ParameterBindings>
           <ParameterBinding Name="CustomNameSortLabels" DefaultValue="Job Title,Department,Last Name" />
           <ParameterBinding Name="CustomNameSortValues" DefaultValue="jobtitle,department,lastname" />
    </ParameterBindings>
    
  2. Create XSLT template named CustomSortOptions for retrieving custom sort options from ParameterBindings property and rendering it

        <xsl:template name="GetCustomSortResultUrl">
        <xsl:param name="NameSortValue"/>
        <xsl:value-of select="concat(concat(concat('peopleresults.aspx?k=',$QueryFromUrl),'&amp;v1='),$NameSortValue)"/>
    </xsl:template>   
     <xsl:template name="CustomSortOptions">
        <xsl:param name="NameSortValues" select="$CustomNameSortValues"/>
        <xsl:param name="NameSortLabels" select="$CustomNameSortLabels"/>
        <xsl:param name="separator" select="','"/>
        <xsl:choose>
          <xsl:when test="not(contains($NameSortValues, $separator))">
            <xsl:if test="string-length($NameSortValues) &gt; 0">
              <xsl:variable name="NameSortUrl">
                <xsl:call-template name="GetCustomSortResultUrl">
                  <xsl:with-param name="NameSortValue" select="$NameSortValues"/>
                </xsl:call-template>
              </xsl:variable>
              <xsl:element name="option">
                <xsl:attribute name="value">
                  <xsl:value-of select="ddwrt:EnsureAllowedProtocol(string($NameSortUrl))"/>
                </xsl:attribute>
                <xsl:if test="$NameSortValues = $V1FromUrl and string-length($HsFromUrl) = 0">
                  <xsl:attribute name="selected">selected</xsl:attribute>
                </xsl:if>
                <xsl:value-of select="$NameSortLabels"/>
              </xsl:element>
            </xsl:if>
          </xsl:when>
          <xsl:otherwise>
            <xsl:variable name="NameSortUrl">
              <xsl:call-template name="GetCustomSortResultUrl">
                <xsl:with-param name="NameSortValue" select="substring-before($NameSortValues, $separator)"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:element name="option">
              <xsl:attribute name="value">
                <xsl:value-of select="ddwrt:EnsureAllowedProtocol(string($NameSortUrl))"/>
              </xsl:attribute>
              <xsl:if test="substring-before($NameSortValues, $separator) = $V1FromUrl">
                <xsl:attribute name="selected">selected</xsl:attribute>
              </xsl:if>
              <xsl:value-of select="substring-before($NameSortLabels, $separator)"/>
            </xsl:element>
            <xsl:call-template name="CustomSortOptions">
              <xsl:with-param name="NameSortValues" select="substring-after($NameSortValues, $separator)"/>
              <xsl:with-param name="NameSortLabels" select="substring-after($NameSortLabels, $separator)"/>
              <xsl:with-param name="separator" select="','"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>   </xsl:template>
    
  3. Place call for this template in XSLT after rendering of standard sort options (Relevance, Social Distance and Name)

    <xsl:if test="$ShowPeopleSortDropdown">
                <label for="sortbydd" id="sortbyddlabel">
                  <xsl:value-of select="$SortBy" />
                </label>
                <select ..>
                  <!-- Standard Sort options goes here  -->
                  <!-- Custom Sort options goes here -->
                  <xsl:call-template name="CustomSortOptions"/>
                </select>
                <xsl:text disable-output-escaping="yes">&#8195;</xsl:text>
     </xsl:if>
    

Please follow my post about customizing People Search Results with Custom Sorting options using XSLT for more details

share|improve this answer
    
Thanks for this. I'll give it a try. How can I go about removing Social Distance as an option? –  LoneWolfPR Feb 27 '13 at 17:07
add comment

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.