Skip to content
October 19, 2011 / red1s

Modifying SharePoint 2010 Standard Search Results


Recently I had to do a complete overhaul of the SharePoint 2010 search results page. Actually it was part of an overall search solution based on SharePoint foundations search engine (I know right, why not FAST) anyhow it had to be done.

We used a combination of XSLT trickery B-D and Metadata Property mappings combined with scopes and a few workflows the objective was achieved (more on the overall solution later)

For now though I’ll just get into how the search results page was updated to output what was required and in essence modify the search results listing page (which for most people seems to be a bit complex)

The tutorial consists of two components:

Metadata properties

XSL Styling

The first Segment of this tutorial will be setting the managed metadata property to output required column info-

I added the required pre created columns as metadata properties from Central Admin

From Central Administration:

clip_image001

Open up metadata properties from the search service applications link:

clip_image002

Create a new managed property:

clip_image003

You’ll need to provide a property name:

clip_image004

Then add a mapping:for the crawled property, which has been crawled and is of the following type: (Text, Integer ,Decimal ,Date and Time ,Yes/No) as other types won’t be picked up

clip_image005

Once you’ve done that make sure you see it in the Mapping to crawled properties:

clip_image006

Then select ‘Use in scopes’ for it to appear in the scopes and ‘Add managed property to the custom result set retrieved on each query’

Once you’ve completed this then update the crawl and complete a full crawl: (Do it twice just in case)

clip_image007

 

 

This is the second section which is the XSLT portion of the tutorial

Go into your search results page – or the page that has your core results webpart:

clip_image008

You’ll need to untick -> Use Location Visualization (Which more info is explained in another one of my blog posts)

clip_image009

QUICK NOTE: ensure that all your xsl variables  are lower case – took me a while to figure that 1 out Smile with tongue out

And make sure to add the newly created metadata property to ‘Fetched Properties’ in the following form: (note my new property at the end)

 

<Columns>

<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"/> <Column Name="PopularSocialTags"/> <Column Name="PictureWidth"/> <Column Name="PictureHeight"/> <Column Name="DatePictureTaken"/> <Column Name="ServerRedirectedURL"/>

<Column Name="ProviderAddress"/>

</Columns>

Once its been added here you’ll need to begin working with your XSLT code which can be accessed by hitting the following button:

clip_image010

Firstly you’ll probably need to see what type of data is coming out of it and if your newly inserted metadata properties are pulling data out successfully.

A good test for this is to template the XSL content in the editor with the following XSLT info:

<?xml version="1.0" encoding="UTF-8"?>

<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="/">

<textarea rows="20" cols="100">

<xsl:copy-of select="*"/>

</textarea>

</xsl:template>

</xsl:stylesheet>

Which outputs the searched content to the page: (not pretty but usable) so you should get something like the below:

clip_image011

Once you’ve noticed that your elements are pulling the correct data out you’d need to then modify the XSLT and require a bit of knowledge around XSLLT, I recommend the following sites for this:

XSL Syntax Basics – http://www.w3schools.com/xsl/xsl_w3celementref.asp

This helped me (If then) – http://geekswithblogs.net/RobBowman/archive/2008/11/18/xslt—if-then-else.aspx and http://our.umbraco.org/forum/developers/xslt/16457-if-then-statement-in-XSLT

Finally how to format search results: http://msdn.microsoft.com/en-us/library/ms584121(v=office.12).aspx (which is very useful to allow you to understand the terms used in the search core results page and their usage )

For instance:

clip_image012

Anyway once you know the above I used the following link: http://sharepoint2010search.codeplex.com/ to restyle my search results page:

This developer has created a styled table with elements that can be used in combination with the previous metadata elements used to create a table of output results with data formatted from the search results

After completing the formatting and addition of the required columns my table now look s like this

clip_image013

Once you are aware of the XSL formatting and other elements of the page you can do a whole host of things to style and work on the outputted results.

Such as ordering the results, adding removing columns and joining content to form complex variable strings based on data returned from the search results:

The following code is a segment for ordering result set info based on the providersequence

<xsl:sort select="providersequence" order="ascending" />

<xsl:sort select="productgroupstring" order="ascending" />

Formatting data rows:

<td class="ms-vb">

<xsl:value-of select="providersequence" />

</td>

<td class="ms-vb">

<xsl:value-of select="productgroupstring" />

</td>

And that’s it , hope you find this insightful and be sure to leave feedback or comments if you have any queries or the like ;-)

References:

SharePoint 2010 video on search results modification- http://www.sharepoint-videos.com/sp10-customize-search-results-using-xslt/

SharePoint Meta data property management – http://www.novolocus.com/2008/05/13/what-columns-can-i-use-in-my-search-results/

http://www.zimmergren.net/archive/2008/03/15/moss-2007-customize-the-search-result-using-xslt-part-3-customize-using-sharepoint-designer-2007.aspx

Sample: Search Core Results Webpart XSLT  -

http://msdn.microsoft.com/en-us/library/ms562390(v=office.12).aspx

About these ads

2 Comments

Leave a Comment
  1. shaik / Oct 23 2012 1:51 pm

    i want custom results page along with refinement panel.how can do this.

Trackbacks

  1. SharePoint 2010 – Adding multiple search core results to one page with different result sets « red1'space

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: