How to: Change the Properties Returned in the Core Search Results
Last modified: June 29, 2010
Applies to: SharePoint Server 2010
To display values from custom properties in the SharePoint Enterprise Search results Web Parts, 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.
Only managed properties are available for search queries. If the custom property is a crawled property, you must map it to a managed property for these steps to work. For more information, see Managing Metadata.
To add a property to the search query
With the search results page open in the browser, click the Site Actions menu, and then click Edit Page Content.
After the page opens in Edit mode, click the drop-down arrow for the Web Part to open the Web Part menu, and then click Edit Web Part. This opens the tool pane so you can modify the Web Part's properties.
Expand the Display Properties node, and then clear the Use Location Visualization check box.
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.
Add a tag with the managed property name within the <SelectedColumns> section, using the following syntax.
Copy the updated XML back into Fetched Properties text box, and then click OK to save the changes to the Web Part.
The property value should now be included in the search resultsthat are returned. You can verify this by using the steps described in How to: View Search Results XML Data.
To display the property as part of the search results, you must modify the Web Part's XSL property.
To modify the Web Part's XSLT to include the new property
Repeat steps 1 and 2 from the previous procedure.
Expand the Display Properties node, and then click the XSL Editor button to open the Text Entry window for the XSL property.
Copy the contents of the window into an XML editor, where you will modify the XSLT code to display the custom property.
The modifications you make depend on how you want to display the property. For this example, you can use the DisplayString template, as shown in the following code.
<xsl:template name="DisplayString"> <xsl:param name="str" /> <xsl:if test='string-length($str) > 0'> - <xsl:value-of select="$str" /> </xsl:if> </xsl:template>
Alternatively, you could create a template for the custom property, and specify this template by using the <xsl:call-template> element. For more information about this process, see the <xsl:call-template> Element reference.
You must add the code to call the DisplayString template to display the custom property. To display the custom property with other metadata, such as the Author property, locate the call-template code for the DisplayAuthors template by searching for the following string:
After the closing the </xsl:call-template> element for the DisplayAuthors template, add the <xsl:call-template> element for the new property by using the following syntax.
<xsl:call-template name="DisplayString"> <xsl:with-param name="str" select="customproperty" /> </xsl:call-template>
The custom property name must contain all lowercase characters.