Display Custom fields in SharePoint 2010 search results webpart

To display your custom fields like for e.g. you want to include department name or site name in your search result along with other metadata, you must modify the Web Parts’ properties to do the following:
* Add the custom property to the search query.
* Modify the XSLT transformation (XSLT) to display the custom property.

Add the custom property to the search query. – To do this follow the below steps :

1. Add a Core Search results webpart to your page.
2. Edit the Page and modify the webpart.
3. Expand the Display Properties node, and then clear the Use Location Visualization check box.
4. Double-click in the Fetched Properties text box to select the text that contains the XML specifying the properties to return, copy it to the clipboard, and then paste it into an editor, such as Notepad or Microsoft Visual Studio.
5. Add a tag with the managed property name under the <SelectedColumns> section
like <Column Name=”departmentname”/gt;

Please Note : Only managed properties are available for search results or advanced search by default. So, before you add anything make sure you have your custom filed ans one of the crawled properties and also you have created and mapped it to a managed property that we are using above. These properties will also be visible in your search center -> Advanced search webpart’s Add the Property restriction section.

6. Next, to display the property as part of your search results webpart, you must modify the Web Part’s XSLT. To do this in the webpart properties, click the XSL Editor button to open the Text Entry window for the XSL property.
7. Add the following template in your anywhere in your xsl

<xsl:template name=”DisplayCustomFiled”>
<xsl:param name=”str” />
<xsl:if test=’string-length($str) > 0′>
<xsl:value-of select=”$str” />
</xsl:if>
</xsl:template>

8. Now make a call to this template where you want to display your custom filed as below

<xsl:call-template name=”DisplayCustomFiled”>
<xsl:with-param name=”str” select=”departmentname” />
</xsl:call-template>\>

Note : The custom property name must contain all lowercase characters.

Comments

  1. Keep posting stuff like this i really like it

Trackbacks

  1. […] Przeczytaj artykuł: Learning SharePoint » Display Custom fields in SharePoint 2010 … […]

Speak Your Mind

*