Purvish's Blog

January 17, 2011

Display Custom fields in SharePoint 2010 Core search Webpart results.

Filed under: Uncategorized — Purvish Shah @ 10:42 pm

 

Hello I am writing blog after almost 2 months.

Task :- Need to add custom fields in Sharepoint 2010 Core Search Web Part

Steps 1 :- You need add your custom filed in Managed Metadata property.If you have FAST Search , you need to add in both place (FAST Search Managed Property and Regular SharePoint Search Managed Property)

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

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

Step 3 :- 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>

NOTE :- FULL CRAWLED is required to see effect in search core result web part.

Create a free website or blog at WordPress.com.