CODEDIGEST
Home » Articles
Search
 

Technologies
 

Sponsored links
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
Want to add a rating field to MOSS search results? Here's how!

By Shai Petel
Posted On Jan 27,2009
Article Rating:
Be first to rate
this article.
No of Comments: 0
Category: Sharepoint/MOSS
Print this article.

Want to add a rating field to MOSS search results? Here's how!

By Shai Petel, VP R&D, KWizCom Corporation

 

Summary

By popular demand I have decided to write a brief "How to" guide, explaining how to add custom fields, specifically a KWizCom Rating field, to the MOSS search results page.

 

In this article we will focus on how to add the custom field to your MOSS search results page but it is important to note that many more things can be achieved using simple XSL editing, for example adding sorting or grouping by special fields.

Now to our task – adding a KWizCom Rating field to your MOSS search results page:

 

This task has to main steps:

Step 1: Add the Rating field to the search Index Engine

Step 2: Customizing the search results page

 

This guide assumes you have installed KWizCom's Rating Field Type and created a field in a list named: “Rate” of type “Rating”.  If you have yet to do so please complete these requirements before you continue.

 

Step 1: Add the Rating field to the search Index Engine

1. Open SharePoint Central Administration

2. Browse to your Shared Services Provider (SSP)

3. At the SSP home page, click “Search Settings”

4. Go to “Metadata Property Mappings” link

5. Click “New Managed Property”

6. Set property name to “Rating”, Type = “Decimal”

7. Select “Include values from a single crawled property based on the order specified”

 

8. Click on “Add Mapping”

9. Search for your tags fields. If you do not see any of your tags fields – you may have to manually crawl the SharePoint content source before you can continue.

 

10. If you have more than one property of type Rating – please search all of them and add them to this list.

11. Click OK twice to confirm the new managed property.

 

Part 2: Customizing the search results page

12. Browse to your search site

13. Go to the results page (or perform a simple search go get there)

14. Click Site Actions -> Edit Page

15. Locate the “Core Results” web part

16. Choose to modify the web part properties

First – we will add the Rating managed property to the results XML:

17. Open the “Results Query Options” group, and click to edit “Selected Columns” property

 




18. Add the Managed Property “Rating” to the Column Names.

19. Next, we will have to edit the XSL for the result item template.

20. Expand the “Data View Properties” tool part, and click “XSL Editor”

 

21. Locate in the XSL the template “<xsl:template match="Result">” and update it to look like this:

<!-- This template is called for each result -->

<xsl:template match="Result">

<xsl:variable name="id" select="id">

<xsl:variable name="url" select="url">

<span class="srch-Icon">

<a href="{$url}" id="{concat('CSR_IMG_',$id)}" title="{$url}">

<img align="absmiddle" src="{imageurl}" border="0" alt="{imageurl/@imageurldescription}" />

</a>

</span>

<span class="srch-Title">

<a href="{$url}" id="{concat('CSR_',$id)}" title="{$url}">

<xsl:choose>

<xsl:when test="hithighlightedproperties/HHTitle[. != '']">

<xsl:call-template name="HitHighlighting">

<xsl:with-param name="hh" select="hithighlightedproperties/HHTitle">

</xsl:call-template>

</xsl:when>

<xsl:otherwise><xsl:value-of select="title"></xsl:otherwise>

</xsl:choose>

 

<xsl:if test="rating > 0">

User Rating: <b><xsl:value-of select="rating"></b>

</xsl:if>

 

</a>

<br/>

</span>

 

<xsl:choose>

<xsl:when test="$IsThisListScope = 'True' and contentclass[. = 'STS_ListItem_PictureLibrary'] and picturethumbnailurl[. != '']">

<div style="padding-top: 2px; padding-bottom: 2px;">

<a href="{$url}" id="{concat('CSR_P',$id)}" title="{title}">

<img src="{picturethumbnailurl}" alt="" />

</a>

</div>

</xsl:when>

</xsl:choose>

<div class="srch-Description">

<xsl:choose>

<xsl:when test="hithighlightedsummary[. != '']">

<xsl:call-template name="HitHighlighting">

<xsl:with-param name="hh" select="hithighlightedsummary">

</xsl:call-template>

</xsl:when>

<xsl:when test="description[. != '']">

<xsl:value-of select="description">

</xsl:when>

</xsl:choose>

</div >

<p class="srch-Metadata">

<span class="srch-URL">

<a href="{$url}" id="{concat('CSR_U_',$id)}" title="{$url}" dir="ltr">

<xsl:choose>

<xsl:when test="hithighlightedproperties/HHUrl[. != '']">

<xsl:call-template name="HitHighlighting">

<xsl:with-param name="hh" select="hithighlightedproperties/HHUrl">

</xsl:call-template>

</xsl:when>

<xsl:otherwise><xsl:value-of select="url"></xsl:otherwise>

</xsl:choose>

</a>

</span>

<xsl:call-template name="DisplaySize">

<xsl:with-param name="size" select="size">

</xsl:call-template>

<xsl:call-template name="DisplayString">

<xsl:with-param name="str" select="author">

</xsl:call-template>

<xsl:call-template name="DisplayString">

<xsl:with-param name="str" select="write">

</xsl:call-template>

<xsl:call-template name="DisplayCollapsingStatusLink">

<xsl:with-param name="status" select="collapsingstatus">

<xsl:with-param name="urlEncoded" select="urlEncoded">

<xsl:with-param name="id" select="concat('CSR_CS_',$id)">

</xsl:call-template>

</p>

</xsl:template>

22. You can only add the following to the existing XSL you already had there instead of pasting the entire tag:

<xsl:if test="rating > 0">

User Rating: <b><xsl:value-of select="rating"></b>

</xsl:if>

23. And you should get results that will resemble this:

 

24. For debugging reasons, should you wish to view the results RAW XML, copy the existing XSL to notepad for backup, and use this XSL instead:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes">

<xsl:template match="/">

<xmp><xsl:copy-of select="*"></xmp>

</xsl:template>

</xsl:stylesheet>

 

These steps are pretty straightforward, I sincerely hope this guide is helpful to you. Should you have any difficulty completing these steps on your own KWizCom offers this customization as a part of our remote consulting services. You are welcome to contact sales@kwizcom.com for more information.

 

For more helpful tips and information please visit KWizCom's official blog: http://kwizcom.blogspot.com/

Similar Articles