This guide will show you how to add custom fields – specifically a KWizCom Rating field to the MOSS search results page.
This article will only demonstrate how to add the field to the results, but much more things can be achieved using simple XSL editing like: Add sorting or grouping by special fields.
This task is mainly done in 2 parts:
Part 1: Add the Rating field to the search Index EnginePart 2: Customizing the search results pageThis article assumes you have installed KWizCom Rating Field Type and created a field in a list named: “Rate” of type “Rating”. If you haven’t done so please complete these requirements before you continue.
Part 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, please 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 simple 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>
Hope this helps, if you have trouble doing it yourself we offer this customization as a part of our remote consulting services, contact sales at kwizcom.com by email for more information on that.
Thanks, Shai Petel.