How to: Change the Properties Returned in the Core Search Results

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.

Note

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

  1. With the search results page open in the browser, click the Site Actions menu, and then click Edit Page Content.

  2. 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.

  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 within the <SelectedColumns> section, using the following syntax.

    <Column Name="CustomProperty"/>
    
  6. 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.

    Note

    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

  1. Repeat steps 1 and 2 from the previous procedure.

  2. Expand the Display Properties node, and then click the XSL Editor button to open the Text Entry window for the XSL property.

  3. 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) &gt; 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.

  4. 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:

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

  5. 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>
    

    Important

    The custom property name must contain all lowercase characters.