This post is over a year old, some of this information may be out of date.
Almost two months ago Pascal Van Vlaenderen asked a question on twitter if there’s a way to specify the Result Source in the QueryString (https://twitter.com/VanVlaenderenP/status/392920559853383680). Since that time, this question was on my to-do list to check this out.
First thing to do is to find out the function where all the properties are set of your search results. All the magic happens in the Srch.U.fillKeywordQuery function. In that function the query text, result source ID, row limits, etx… are set.
To not completely rewrite the fillKeywordQuery function, we are going to store the reference to the original function, and call this at the end.
You don’t need to write a lot of code to dynamically change the result source. What I wanted to achieve is when I used
<pictures> as a keyword in the search box, it should dynamically change the result source. My code looks like this:
This piece of code can be added in a Script Editor Web Part on the results page of your search center.
To know the IDs of your search results, you can navigate to the Site Settings > Search Result Sources (under the Site Collection Administration section) > Click on the result source > you’ll find the Result Source ID in the URL.
Note: at the moment this isn’t working togheter with the search refiners. Right now when you’re going to refine the results, the custom keyword will be removed. This is something new on my to-do list.