Wednesday, 30 November 2011

Search Refiners and the Search Box

​Something that isn't normally the case is to remove the Search Box from the out-of-the-box search results page. More often than not, it's a requirement to have it present so the user can see the query they're currently searching with. However, recently, a client insisted on removing this from their search results page.

Now, I've already given the game away here in the title of this article: some of the search refiners functionality stopped working. Which bit? Well, nothing overly important - simply the "show more" option that appears in the refiners when more than a specified number of refiners are present. More to the point is why it happens?

Having examined pages with and without the Search Box, it appears the Search Box Web Part is responsible for adding a JavaScript function and a reference to the search.js file. The function is effectively a check for the search.js, but without it the "show more" option will fail as it calls this function first and as it can't find it, it doesn't work.

The following was an extract I added to my Search Results Xslt to get the page to function correctly:

function SearchEnsureSOD() {
    EnsureScript('search.js', typeof(RenderTaggingControl));

The "typeof" used by the EnsureScript function call is usually against GoSearch but this is present only when the Search Box Web Part is present. I've used RenderTaggingControl instead as this is present when the refiners are present.

No comments:

Post a Comment