Include SharePoint item rating in search results

Table of Contents

If you enabled for your users to use rating feature in SharePoint 2010 – they will likely to get used to it and would like to see it in more places and search is first on the list.

Here is how you’d go about enabling item rating on each item in search results:

1. Naigate to your search page and in the edit mode of your page select Edit Webpart on the Search Core Results WP

2. Now in the DisplayProperties -> Fetched Properties add the following item to the list of fetched columns:

<Column Name=”Rating”/>

3. Cick XSL Editor button right below the Fetched Properties field. You will see quite a bit of XML in the following window so paste it to Notepad and find the following line of code:

<xsl:call-template name=”DisplayAuthors”>

and paste the following code right above it. This will make sure the rating control appears right before the author information in the search results:

<xsl:choose>
<xsl:when test=”rating > 0″>
      <span>
       <xsl:attribute name=”title”>
        <xsl:value-of select=”rating”/>
       </xsl:attribute>
       <xsl:call-template name=”stars”>
        <xsl:with-param name=”starCount” select=”rating”/>
       </xsl:call-template>
       <xsl:if test=”round(rating) > rating”>
        <img src=”/_Layouts/Images/Ratings/RatingsNew.png”/>
       </xsl:if>
      </span>
      <br/>
     </xsl:when>
     <xsl:otherwise>
      <b>Not Rated</b>
      <br/>
     </xsl:otherwise>
    </xsl:choose>
<xsl:choose>

4. Now scroll down the XML find the section where you see definitions of various templates, here is hwo we’re going to implement the template for the  rating, paste the following:

<xsl:template name=”stars”>

 <xsl:param name=”starCount”/>

 <xsl:param name=”value” select=”1″/>

 <xsl:if test=”$value &lt;= $starCount”>

  <img src=”/_Layouts/Images/Ratings/RatingsNew.png”/>

  <xsl:call-template name=”stars”>

   <xsl:with-param name=”starCount” select=”$starCount”/>

   <xsl:with-param name=”value” select=”$value + 1″/>

  </xsl:call-template>

 </xsl:if>

</xsl:template>

5. Lastly, we need to provision te Rating search preoperty (column we’re going to grab a data from). In your central admin Service Applications (http://[central admin URL]/_admin/ServiceApplications.aspx) highligh Search Service Administration  and click Manage on the ribbon.

6. Pefrom a full search crawl which you can initiate from Content Sources  left nav link. Wait for the crawl to complete.

6. Pick Metadata Properties from the left nav menu and click New Managed Property from the newly opened page.

7. For name of the property type Rating of ty Decimal , then click Add Mapping

8. In the new modal box search for rating  and pick column name that will be of the type of decimal.

9. Click OK to add new managed property.

That’s it. Now search results will include a image representing a rating for each search result and if some items have not been rated they will have “Not rated” instead.

Good luck!

http://www.sharemuch.com/2010/03/01/include-sharepoint-2010-rating-in-search-results-webpart/

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Hosted generously by CustomWare