How to Customize Search Results in SharePoint 2010

Consider this; users want to be able to see the Document Type name for each search result item. In addition, users want to remove the URL listed at the bottom of the summary section of the search result item. The URL confuses the user and prevents easy reading of the summary document. To address this issue, add the Document Type managed property to the displayable properties of the Web Part. We have to modify the XSLT transformation XML to display this property in the search results. Finally, modify the XSLT so the document's URL is not displayed.

Add the Document Type managed property to the displayable properties of the Search Core Results Web Part.

  1. Navigate to your web site.
     
  2. Click Site Actions, and then click Edit Page.
     
  3. Locate the Bottom zone in the Web Part page.
     
  4. Locate the Search Core Results Web Part.
     
  5. Hover your mouse over the upper-right corner of the Web Part until a down arrow displays. Click the down arrow to display the Web Part menu.

    9.png
     
  6. Click Edit Web Part.
     
  7. Locate page the Search Core Results tool pane in the upper right corner of the Web Part.
     
  8. Expand the Display Properties section.
     
  9. Uncheck the Use Location Visualization check box.
     
  10. Copy the text in the Fetched Properties text box into Notepad.

    10.png
     
  11. Add <Column Name="DocumentType"/> to the end of the text before closing the </Columns> XML element.
     
  12. Replace the existing text with a copy of all the text from Notepad to the Fetched Properties text box in the Search Core Results Web Part.
     
  13. Click the Apply button.
     
  14. Check and then uncheck the Use Location Visualization check box to enable the XSL Editor button for the next exercise.

Modify the XSLT Transformation XML to Display the Document Type Managed Property in the Search Results

  1. Click the XSL Editor button to open the XSLT transformation XML.
     
  2. Locate the <div class="srch-Metadata2"> element in the editor.
     
  3. Insert the following XSL template at the indicated location:

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

    <xsl:with-param name="str" select="documenttype" />

    </xsl:call-template>

    11.png
     
  4. Click the Save button.
     
  5. Click the OK button from the Search Core Results tool pane.
     
  6. Click the Save and Close ribbon button to save and close the results.aspx page.
     

Modify the XSLT Transformation XML to Remove the URL from the Search Results Metadata

  1. Click the XSL Editor button to open the XSLT transformation XML.
     
  2. Locate the <p class="srch-Metadata1"> element in the editor.
     
  3. Remove the span element as indicated by the highlight.

    12.png

     
  4. Click the Save button.
     
  5. Click the OK button of the Search Core Results tool pane.
     
  6. Click the Save and Close ribbon button to save and close the results.aspx page.
     
  7. Type Microsoft in the Search box and execute a search to see the content type in the summary section of the results. Note that the URL is not displayed at the bottom of the metadata summary.


13.png

Up Next
    Ebook Download
    View all
    Learn
    View all