Freigeben über


Customizing SharePoint 2007 Search Result for Structured Content

The out of the box Search Core Result web part displays search result in a format that is best suited for unstructured content. With results laid out vertically highlighting content that matches the search criteria, it provides end users to quickly skimp through the result set. Though this format is best suited in scenario where the search result contains unstructured data from various content sources - SharePoint, File System, Web, and LOB - it doesn't do justice when users need to search only structured content.

While databases such as SQL Server is great for transactional structured data, SharePoint excels in collaborative structured as well as unstructured data. Before we go any further, for the purpose of this discussion, structured data is one that is stored in row and column format. It's called structured because column provides specific meaning / context to the data. Whereas, unstructured content is not represented by row and column. For example, content in Word document or a PDF document. In SharePoint you could bring structured data and unstructured content together in either a List, which allows user to capture metadata along with attachments; or a document library, which allows user to maintain documents along with metadata. This combination of metadata and documents is what brings structured data and unstructured content together in SharePoint. This post is not about structured and unstructured content, but wanted to provide a context on need for displaying search result in tabulat format.

More often than not, enterprises would use some form of List to manage content specific to a purpose (for e.g. knowledge repository). Metadata management is best achieved by using Site Columns and Site Content Types. Based on my experience when user searches within a list, they would like to see results laid out in tabular format, arranged in rows and columns, rather than the out of the box search result format. There are many good blog posts that explains usage of SPGrid and some form of coding to display search result in form of DataGrid. While SPGrid provides rich features such as filtering and context menu, it also requires effort for coding, testing and deployment. If your objective is to just display the results in tabular format with metadata as columns and results arranged in rows, then you could get away by simply changing the Search Core Result XSLT.

Lets consider we have a knowledge repository in SharePoint. This repository is in form of List that is mapped to a Site Content Type named KnowledgeBase. KnowledgeBase has 4 site columns: Title, Knowledge Author, Group and Summary. One of the items in this repository is title MOSS Global deployment, with "Knowledge Author" as "John Doe", Group as "Manufacturing" and some text in the Summary column. Without any kind of XSLT customization, when user searches on this list for "MOSS Global", they will see result in format below

Sharepoint OOB Search Result

After we customize the search result XSLT the result format will look like this:

Customized Search Result in Tabular format

Note that the Title is hyperlink pointing to the url of the content. Since we are using the same web part, all other web parts such as Search Actions, Search Summary and Search Paging will work as usual without any change. What we have done is simply changed the XSLT.

Before we change the XSLT, we will need to define the metadata as managed properties. We will create following managed property:

  1. KAuthor: Mapped to Knowledge Author column
  2. KSummary: Mapped to Summary column
  3. KGroup: Mapped to Group column

We don't need to define Title and Last Modified as they are already defined in SharePoint.

In order to include newly created managed properties in XSLT, they need to be included in the "Selected Columns" property of the Search Core Result Web Part.

Modify the Search Core Result Web Part by clicking on the "Edit" link. Expand the "Results / Query Options" section. Include KAuthor, KSummary and KGroup in the "Selected Columns" as shown below.

<root xmlns:xsi=" https://www.w3.org/2001/XMLSchema-instance" >

<Columns>           

<Column Name="KGroup"/>

<Column Name="KAuthor"/>

<Column Name="KSummary"/> <Column Name="WorkId"/><Column Name="Rank"/> <Column Name="Title"/><Column Name="Author"/><Column Name="Size"/>    

<Column Name="Path"/><Column Name="Description"/><Column Name="Write"/> <Column Name="SiteName"/><Column Name="CollapsingStatus"/>            

<Column Name="HitHighlightedSummary"/>

<Column Name="HitHighlightedProperties"/> <Column Name="ContentClass"/> <Column Name="IsDocument"/><Column Name="PictureThumbnailURL"/>      

  </Columns>  

</root>

It is important to understand the XML returned by the Sharepoint Search engine. The XML returned has all the columns defined in "Selected Columns" property of the web part. The XML looks like this:

<All_Results>
<Result>
<id>1</id>
<kgroup>Manufacturing</kgroup>
<kauthor>John Doe</kauthor>
<ksummary>This knowledge article outlines challanges and best practice recommendation on implementation of Sharepoint on global platform.</ksummary>
<workid>1123</workid>
<rank>497</rank>
<title>MOSS Global Deployment</title>
<author>System Account</author>
<size>0</size>
<url>
https://myportal-18e67cd/sites/Knowledge/Lists/KnowledgeArticles/DispForm.aspx?ID=1 </url>
<urlEncoded>http%3A%2F%2Fmyportal%2D18e67cd%2Fsites%2FKnowledge%2FLists%2FKnowledgeArticles%2FDispForm%2Easpx%3FID%3D1</urlEncoded>
<description></description>
<write>4/1/2008</write>
<sitename>
https://myportal-18e67cd/sites/knowledge </sitename>
<collapsingstatus>0</collapsingstatus>
<hithighlightedsummary> <ddd /> of Sharepoint on <c1>global</c1> platform. <ddd /> <c0>MOSS</c0> <c1>Global</c1> Deployment <ddd /> <c0>MOSS</c0> <c1>Global</c1> Deployment </hithighlightedsummary>
<hithighlightedproperties> <HHTitle> <c0>MOSS</c0> <c1>Global</c1> Deployment</HHTitle> <HHUrl>
https://myportal-18e67cd/sites/Knowledge/Lists/KnowledgeArticles/DispForm.aspx?ID=1 </HHUrl> </hithighlightedproperties>
<contentclass>STS_ListItem_GenericList</contentclass>
<isdocument>0</isdocument>
<picturethumbnailurl></picturethumbnailurl>
<imageurl imageurldescription="Result of type: document">/_layouts/images/STS_ListItem16.gif</imageurl>
</Result>
</All_Results>

Now that we have done the ground work, next we modify the Search Core Result XSLT. Following link has the XSLT to display results in tabular format.

 

 

 

Modified Search Core Result XSLT

Open the XSLT in XSLT editor such as Visual Studio.NET 2008. Line 126 to Line 133 contains XSLT processing for displaying the column header. You could add your own columns here. Line 149 to Line 168 contains processing for displaying search result in table. You could replace managed properties shown here with your own managed properties. You could include any of the other XML elements from XML returned from Search.

Cheers,

Arbindo

Comments

  • Anonymous
    April 13, 2008
    Great Article!I have done this for a client as well. I created the XSLT to make the results look like a document library view. In this same view i also want to add an edit link so people can easily edit metadata for the document. The link goed to EditForm.aspx?ID= .... i have used the workid column for this. This works for some documents, however.. most of the documents give an error that the specified document does not exist or has been moved.Comparing the workid in the searchresults to the ID shown in the edit url within the document library view gives me 2 different ID's.Any clue?
  • Anonymous
    April 15, 2008
    The comment has been removed
  • Anonymous
    May 12, 2008
    I'm also working on the "edit url" link, only problem i'm facing at the moment, is how to get the library name of the document as a managed property in the search results. I need this name as it is a part of the url i'm dynamically building.Any ideas someone?
  • Anonymous
    May 13, 2008
    The comment has been removed
  • Anonymous
    May 15, 2008
    The issue after customizing search resutls using Sharepoint designer in this way is that it doesn't highlight the search keyword in the results...Can we resolve this ??
  • Anonymous
    May 20, 2008
    The comment has been removed
  • Anonymous
    August 30, 2008
    I am having the same problem as Rens, can you be a little more descriptive as to how you implemented your edit link...
  • Anonymous
    September 02, 2008
    The comment has been removed
  • Anonymous
    February 22, 2009
    Do you know how to add sorting to the tabular search results? The sorting should work across the entire result set and not the paged result set
  • Anonymous
    February 22, 2016
    Great Article and a long time ago. Does anyone have a link that works for the XSLT? Link below does not work. :( Modified Search Core Result XSLT