Friday, January 28, 2011

Using the SharePoint Search “Best Bet” feature to redirect to a landing page

As described on TechNet:
Best Bets are recommended results. Best Bets can link to recommended Web sites, data stores, and documents. When a user includes a keyword or one of its synonyms in a query, the search results page features links to its associated Best Bets in a prominent position.
This can look something like this for the search term “search” on my sample site:
image

In order to turn this into a landing page redirect we will change the uri scheme and edit the Best Bet web part xslt. By using this method you might see a quick flicker of the page before the redirect, but compared to the work involved it might be a small price to pay.

First we need to add a new Best Bet term. We do this by navigating to the site collection settings page where your search center site is hosted and choose “FAST Search keywords”. This should also work if you are not using FAST, but you have to choose “Search keywords” instead.

image

Next click “Add Keywords”

image

Enter your search term, in this example “search” and click OK.

image

Hover your mouse over your search term, click the down arrow and select the “Add Best Bet” link. (Adding a Best Bet for regular search looks a bit different, but the procedure is more or less the same)

image

Enter a title and note that I instead of “http”, enters “redirect” in front of the url

image

Navigate to the search result page and enter edit mode. Next edit the Best Bet web part.

image

Under “Data View Properties” open the XSL Editor. If you copy out the xsl you will around line 67 add the following code:

<xsl:if test="substring($url,1,9) = 'redirect:' and $IsDesignMode = 'False'">
<script>
window.location = "http:<xsl:value-of disable-output-escaping="yes" select="srwrt:HtmlAttributeEncode(substring($url,10))" />";
</script>
</xsl:if>

image

The added xsl will check for url’s starting with “redirect”, and use javascript to redirect to the actual url.

After saving the changes to the web part and the page, try to search for your defined best bet term, and you should be redirected.

[Also postet at http://nuggets.comperio.no]

No comments:

Post a Comment