Wednesday, July 29, 2015

How to do a light weight search center using osssearchresults.aspx (part 3/3)

In the two previous posts I showed how to change the scopes shown in the search drop-down boxes as well as how to modify what is shown on the search page itself using JavaScript injection.

Next up is changing what data is shown on the result page itself. When you do a wildcard search using * you get all kinds of items on the osssearchresults.aspx page. One common ask is to remove container type items like views and folders. On a search center we would either change the web part query template itself or target it using a custom result source to accomplish the filtering.
Using a custom result source is exactly what we’ll do, but the trick is to set this result source to the be default one as osssearchresults.aspx will always use the default result source.

On your site, navigate to site settings and result sources and create a new result source. The following filter will remove all views and container type items from the results.

{searchTerms} -contentclass:STS_List_* iscontainer<>1


So instead of getting


we get


NOTE! The default result source is also used for in-line searching in lists and libraries, so make sure you don’t add a filter to the query which breaks this.