Good news – it really is very easy to have links to pre-filtered search pages (search pages with active refiners). This post will give an example of linking to search page with a single active refiner but you should be able to extend the example to more complex scenarios if you wish.
EDIT: I have written a more recent post which provides JavaScript functions to generate these links dynamically
Cut to the chase
This is what you are looking for, I’ll explain it in depth below:
<Server Relative URL of Search Page>
#Default=%7B%22k%22:%22%22,%22r%22:%5B%7B%22n%22:%22
<Managed Property Name>
%22,%22t%22:%5B%22%5C%22ǂǂ
<HEX Encoded Managed Property Value>
%5C%22%22%5D,%22o%22:%22OR%22,%22k%22:false%7D%5D%7D
e.g.
/search/Pages/results.aspx
#Default=%7B%22k%22:%22%22,%22r%22:%5B%7B%22n%22:%22
RefinableString08
%22,%22t%22:%5B%22%5C%22ǂǂ
506f6c696379
%5C%22%22%5D,%22o%22:%22OR%22,%22k%22:false%7D%5D%7D
You can quickly perform HEX encoding using an online tool such as this.
(The above URLs have been separated on to new lines for readability but should not contain any white space)
Breaking it down
As you have probably already noticed, by applying a filter to a search results page you are appending a hash (or anchor) to the query string. This value is a URL encoded JSON object. Once decoded it looks something like this:
You can quickly perform URL decoding using an online tool such as this.
Importantly for our purposes we can see the name of the managed property on which we are refining “RefinableString08”.
The value is a little more obfuscated. The value ‘5265706f7274’ is in fact the HEX encoded value which we want to refine on. It is vital the “t” property is set to this value prepended by the two “ǂ” characters. The “m” property appears to define a mapping between the HEX encoded value and original value but it does not appear to be necessary.
Reducing the length to fit such that it can be used as a ‘Simple Link’ in a navigation term
A navigation term only supports a limited number of characters in its ‘simple link’ field, approximately 260. This means that the full encoded JS object as above will breach this limit if the managed property value is greater than about 8 characters (if using a ‘RefinableStringXX’ managed property). Not great. However, it turns out that the “m” property of the object is optional, at least when performing simple refinement as we are here. The example I provided at the top of this post has this property excluded in order to reduce it’s length.
Paul.
nice post Paul!
Thanks