Include SharePoint item rating in search results

Version 1 by Yaroslav Pentsarskyy
on Mar 01, 2010 20:18.

compared with
Current by Yaroslav Pentsarskyy
on Mar 01, 2010 20:23.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (29)

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

[|http://www.sharemuch.com/wp-content/uploads/2010/03/search-core-reults-webpart.JPG]

!http://www.sharemuch.com/wp-content/uploads/2010/03/search-core-reults-webpart.JPG|border=1!


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

*_<Column Name=”Rating”/>_*
<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”>_*
<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:

{code}

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

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<xsl:when test=”rating > 0″>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<xsl:attribute name=”title”>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<xsl:value-of select=”rating”/>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</xsl:attribute>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<xsl:call-template name=”stars”>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<xsl:with-param name=”starCount” select=”rating”/>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</xsl:call-template>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<xsl:if test=”round(rating) > rating”>

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

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</xsl:if>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br/>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</xsl:when>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<xsl:otherwise>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<b>Not Rated</b>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br/>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</xsl:otherwise>

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</xsl:choose>

{code}


{code}

<xsl:template name=”stars”>

&nbsp;&nbsp; &nbsp;<xsl:param name=”starCount”/>
<xsl:param name=”starCount”/>

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

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

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

&nbsp;&nbsp; &nbsp; &nbsp;<xsl:call-template name=”stars”>
<xsl:call-template name=”stars”>

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

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

&nbsp;&nbsp; &nbsp; &nbsp;</xsl:call-template>
</xsl:call-template>

&nbsp;&nbsp; &nbsp;</xsl:if>
</xsl:if>

&nbsp;&nbsp;</xsl:template>

{code}

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

6. Pefrom a full search crawl which you can initiate from&nbsp;*{_}Content Sources{_}*&nbsp; left nav link. Wait for the crawl to complete.

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