How to customise search core results web part Part1

Posted by ybbest on YBBest See other posts from YBBest or by ybbest
Published on Tue, 13 Mar 2012 00:11:43 +0000 Indexed on 2012/03/19 2:17 UTC
Read the original article Hit count: 757

In this post, I’d like to show you how to customise search core results web part. It is a quite simple, most of the times what you need to do is to change the xslt to perform the changes. Here are the steps:

1. You need to change the xslt to the following, so that you can see the raw xml.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<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>

a. To do so , you need to go to edit page>>Edit search core results web part >>Display Properties and then untick use Location Visualization


b. Open the xslt editor and copy the existing XSLT code to your preferred xslt editor so that you can customise it.

c. Now you can paste in the XSLT code above.

2.Perform the search after you have completed step1 and you will see the search results returned in raw xml

<All_Results>
    <Result>
      <id>1</id>
      <workid>678</workid>
      <rank>100000000</rank>
      <title>Ybbest</title>
      <author></author>
      <size>137531</size>
      <url>http://ybbest</url>
      <urlEncoded>http%3A%2F%2Fybbest</urlEncoded>
      <description>Ybbest test site</description>
      <write>3/17/2012</write>
      <sitename>http://ybbest</sitename>
      <collapsingstatus>0</collapsingstatus>
      <hithighlightedsummary>
        <c0>Ybbest</c0> test site <ddd /> Add a new image, change this welcome text or add new lists to this page by clicking the edit button above. You can click on Shared Documents to add files or on the <ddd /> </hithighlightedsummary>
      <hithighlightedproperties>
        <HHTitle>
          <c0>Ybbest</c0>
        </HHTitle>
        <HHUrl>http://<c0>ybbest</c0></HHUrl>
      </hithighlightedproperties>
      <contentclass>STS_Site</contentclass>
      <isdocument>False</isdocument>
      <picturethumbnailurl></picturethumbnailurl>
      <popularsocialtags />
      <picturewidth>0</picturewidth>
      <pictureheight>0</pictureheight>
      <datepicturetaken></datepicturetaken>
      <serverredirectedurl></serverredirectedurl>
      <fileextension></fileextension>
      <ows_metadatafacetinfo></ows_metadatafacetinfo>
      <imageurl imageurldescription="SharePoint Site Collection">/_layouts/images/siteicon_16x16.png</imageurl>
    </Result>
 <TotalResults>69</TotalResults>
    <NumberOfResults>50</NumberOfResults>
  </All_Results>

3. Then you can read what has been returned in the raw xml and start modifying the xslt to customise your search results page.

4.You can also link an external xslt to the web part.It can be set in the Miscellaneous of Web Part section.

You can also set it pragmatically using a feature receiver , you can download the source code to do so here.

References:

http://stackoverflow.com/questions/6548104/change-xslt-of-the-searchresultwebpart-during-the-featureactivated

http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/04/05/a-quick-guide-to-coreresultswebpart-configuration-changes-in-sharepoint-2010.aspx

http://www.tonytestasworld.com/post/2011/01/30/HowTo-display-SharePoint-Search-results-as-raw-XML.aspx


© YBBest or respective owner

Related posts about SharePoint 2010

Related posts about enterprise search