On several sites we have links that trigger searches by passing the term GUID to the search page through the 'k=' parameter, as you can see from the URL. This is a neat way of showing all items tagged by a certain term. In fact you can use this method to pass any search string to a search page, not just metadata guids (example: ...resultpage.aspx?k=author:someone).
So this actually works great, but for one thing. I would like to not display the rather cryptic search string in the search box. In addition to the core search results web part on a search page the search box web part also picks up the value passed into the page by the 'k=' parameter, and displays it as the current searched for string.
One solution is to deselect the 'Display submitted search' option in the search box web part properties configuration, but I choose not to because I would like normal search strings entered in the box by the users to display.
After doing a lot of searching for alternatives one of my local MVPs, Mikael Svenson, came up with the easy solution: use the 'a=' parameter instead of 'k='. Has exactly the same effect on filtering the core search results web part, but without displaying the search string in the search box.
One important thing to note is that the core search results web part needs an additional value. Just passing in a value for the 'a=' parameter will return nothing. In my case I added a simple additional query in the 'Append text to query' field in the core results edit web part properties. I used 'IsDocument=1' because I want the search page to list all documents within the defined search scope to be listed if no other search string is given by the user.
Showing posts with label Core search results. Show all posts
Showing posts with label Core search results. Show all posts
Thursday, December 19, 2013
Thursday, November 21, 2013
Tweaking search results xslt to get document titles to open documents directly in browser instead of Office client
In a recent BI-project we needed lots of Excel files to be opened directly in the Excel web app also when found through search. All libraries were configured to open documents in the web browser, but even so search results always lists all document titles to open in Office clients.
In addition to displaying the document title, the author, description, ++, the default search results also display a separate 'View in browser' link for each document. So the logic was to get the functionality of this link to work for the item document titles instead.
This is quite easy to fix. You have to go into the XSLT file that controls how the search output is put together and do three minor changes. This is preferably done through SharePoint Designer.
I really, really advice you to not do these changes directly in the XSLT found in the web part properties of your search core results web part, but rather create your own XSLT file in SharePoint Designer and link this to your web part like described in Matthew McDermott's great blog.
In your copy of the original XSLT - do the following:
This should do the trick. All items listed in your search results should now open in the web browser rather than in clients.
In addition to displaying the document title, the author, description, ++, the default search results also display a separate 'View in browser' link for each document. So the logic was to get the functionality of this link to work for the item document titles instead.
This is quite easy to fix. You have to go into the XSLT file that controls how the search output is put together and do three minor changes. This is preferably done through SharePoint Designer.
I really, really advice you to not do these changes directly in the XSLT found in the web part properties of your search core results web part, but rather create your own XSLT file in SharePoint Designer and link this to your web part like described in Matthew McDermott's great blog.
In your copy of the original XSLT - do the following:
Here is the code that replaces the original div for srch-Title3:
<div class="srch-Title3"> <!-- call custom template to show link to doc that opens in browser--> <span> <xsl:call-template name="TitleOpensInBrowser"> <xsl:with-param name="browserlink" select="serverredirectedurl" /> <xsl:with-param name="currentId" select="$currentId" /> </xsl:call-template> <xsl:text disable-output-escaping="yes">&nbsp;</xsl:text> </span> </div>
Here is the custom template code that I've put right below the original ViewInBrowser template code:
<!-- Custom template to fetch doc title into link that opens in browser--> <xsl:template name="TitleOpensInBrowser"> <xsl:param name="browserlink" /> <xsl:param name="currentId" /> <xsl:if test="string-length($browserlink) > 0"> <span class="srch-urllink BISearchResultsUrlLink"> <a href="{$browserlink}" id="{concat($currentId,'_VBlink')}"><xsl:value-of select="title" /></a> </span> </xsl:if> </xsl:template>
Also there is the param definition right at the top of the file:
<xsl:param name="TitleOpensInBrowser" />
This should do the trick. All items listed in your search results should now open in the web browser rather than in clients.
Subscribe to:
Posts (Atom)


