Wednesday 16 March 2016

How to limit search results to the current site collection in Sharepoint 2013

By default in Sharepoint whole web application is crawled and content from all site collections in this web application is shown on all site collections. What to do if you need to limit search results to the current site collection only, i.e. when you perform search on /sites/test1 site collection, it will show content only from this site collection on search results page? You can create new content source in search service application, specify URL of specific site collection and then configure search results web part to use this specific content source. However this approach requires more work, and if you have a lot of site collection, it will be significant disadvantage.


There is another simpler way to limit search results to the current site collection. Go to Site settings > Search results source and create new default result source (I wrote about how to do it in the following post: Exclude AllItems.aspx from search results in Sharepoint 2013). After that you need to modify Query transform field of the copied result source: add the following rule “Path:{SiteCollection.URL}”. E.g. if you used Local SharePoint Results result source as a base, then you should have the following rules:

{?{searchTerms} -ContentClass=urn:content-class:SPSPeople Path:{SiteCollection.URL}}

After this save the result source. If it is set by default, then OTB search results web parts will use it without additional actions.

No comments:

Post a Comment