Search results provided by Azure Search - read how I built it in this post.
Max Melcher

2 minute read

Recently I read a blog post how to customize the core result webpart - thats the webpart showing the results after you do a search with SharePoint 2010. The the output was modified so that you can click on a link to open the library/folder containing the document you searched - quite handy in my eyes.

The solution for SharePoint search is quite easy, just add

<xsl:if test="isdocument = 'True'">
<xsl:attribute name="href">
<xsl:value-of select="sitename"/>
View Folder

and you are good to go (more details in the mentioned blog post).

The Problem

If you are doing the same thing with FAST for SharePoint (FS4SP) it does not work. The propertysitename is not filled with the location of the document, the FAST crawler extracts, what it should - the sitename.

The Solution

So I started up Visual Studio, copied the xslt and the search result xml and created a little xslt function to extract the path to a document and to show a link:

<!-- changes for Open Library-->
 <div class="{$docPreviewStyle} srch-Metadata2" style="margin-bottom:20px;">
 <xsl:if test="isdocument = 'True'">
 <xsl:attribute name="href">
 <xsl:call-template name="build-location-link">
 <xsl:with-param name="list" select="path" />
 View Location

In the xstl search for the comment “<!- END Additional links ->” - add my code after the closing <div>, thats arround row number 655.

Then add the template “build-location-link” close to the end of the xslt. I added mine right before the comment “<!- End of Stylesheet ->“. That should be line number 968.

<xsl:template name="build-location-link">
 <xsl:param name="list" />
 <xsl:variable name="first" select="substring-before($list, '/')" />
 <xsl:variable name="remaining" select="substring-after($list, '/')" />
 <xsl:value-of select="$first" />/<xsl:if test="substring-after($remaining, '/')">
 <xsl:call-template name="build-location-link">
 <xsl:with-param name="list" select="$remaining" />

The result should look like this:

In my eyes the xslt is not the most elegant solution (any way to remove the recursion with xslt?) - but - I tested it in several installations now - the users loves it!

If you have trouble copy/paste all out of this file: FAST Open Library XSLT.

Further improvements?

So how did you modify the search results - any modifications worth to share?

comments powered by Disqus