Viewing Search Results in raw XML Format


When you use the FAST Search for SharePoint 2010 or the Enterprise Search Service in SharePoint, the default way in which search results are rendered is thru the Core Results Webpart. This webpart gets an XML document as input from the Search Service and uses an XSLT style sheet to customize their appearance before displaying them. A lot of requirements related to changing the way in which search results are rendered, can be accomplished by modifying the default XSLT used by the web part.

For example, in my test environment I have the same image uploaded in a Picture Library as well as a Document Library. When I search for a term which causes both of these images to be returned in the search results, you will notice that the item returned from the Picture Library is displayed using a Thumbnail, whereas the item returned from the Document Library is rendered differently.

To explore why these two items are rendered differently in the search results, we can edit the properties of the Search Core Results Web Part and inspect the XSLT.

Under the Core Results category in the Editor Pane, expand the Display Properties section and click on XSL Editor. You will need to clear the Use Location Visualization checkbox.

The XSLT is almost 720 lines long and it would be better to use some XML Editor to understand it. Somewhere in the XSLT is a condition which checks if the current item is coming from a Picture Library and if there is a thumbnail present. If yes, then it proceeds to render the thumbnail or a generic image.

Not only is this XSLT useful for altering the way in which search results are rendered, it is also useful for debugging and understanding better how search results are actually returned.

For debugging purposes, it is better to view the raw XML returned by the Query Service. So typically in my development environment, I always recommend developers to look at the raw XML returned for accomplishing a variety of tasks related to Search.

  1. Assuming you have a site created using the Enterprise Search Center or FAST Search Center template, go to the search center site and create a new publishing page.

  1. Give XML Results as the Title and XMLResults.aspx as the URL Name. Select Search Results as the Page Layout. Click Create.

  1. Save and Close the newly created page.
  2. Edit the default.aspx page in the Search Center. Click Add New Tab.

  1. Specify Tab Name as XML and XMLResults.aspx (or whatever page you created in the previous steps) as the Page. Click Save.
  2. Click on the newly created XML tab.

 

  1. You should be redirected to the XMLResults.aspx page. Edit this page and repeat the previous step to add the same XML Tab on this page as well.
  2. To ensure that when we type a search query in the XML tab, the search results are displayed in the XML tab and not in the All Sites tab, edit the Search Webpart.

  1. Expand the Miscellaneous category and type XMLResults.aspx in the Target Search results page URL textbox. Click OK.

  1. While the page is still in Edit mode, edit the properties of the Search Core Results web part as well.

  1. Expand Display Properties and click on XSL Editor. You may need to disable the Use Location Visualization checkbox to be able to click on the XSL Editor Button.
    Delete the original XSLT and replace it with the following and then click OK.

<?xml version=”1.0″ encoding=”UTF-8″?>

<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”&gt;

<xsl:output method=”xml” version=”1.0″ encoding=”UTF-8″ indent=”yes”/>

<xsl:template match=”/”>

<xmp><xsl:copy-of select=”*”/></xmp>

</xsl:template>

</xsl:stylesheet>

 

  1. Save and Close the page.
  2. Type a search query in the Search box of the XML Tab. This time you should see search results in their raw XML format.

Advertisements

One Response to Viewing Search Results in raw XML Format

  1. Pingback: Restricting Search Results to contain only List Items / Documents « nauzadk

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: