Using the SharePoint Search “Best Bet” feature to redirect to a landing page
[Cross-posted from Tech And Me]
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:
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.
Next click “Add Keywords”
Enter your search term, in this example “search” and click OK.
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)
Enter a title and note that I instead of “http”, enters “redirect” in front of the url
Navigate to the search result page and enter edit mode. Next edit the Best Bet web part.
Under “Data View Properties” open the XSL Editor. If you copy out the xsl you will around line 67 add the following code:
1 2 3 4 5 |
<span class="kwrd"><</span><span class="html">xsl:if</span> <span class="attr">test</span><span class="kwrd">="substring($url,1,9) = 'redirect:' and $IsDesignMode = 'False'"</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">script</span><span class="kwrd">></span> window.location = <span class="str">"http:<xsl:value-of disable-output-escaping="</span>yes<span class="str">" select="</span>srwrt:HtmlAttributeEncode(substring($url,10))<span class="str">" />"</span>; <span class="kwrd"></</span><span class="html">script</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">xsl:if</span><span class="kwrd">></span> |
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.