Set default scope for Advanced Search Webpart

In this article, I will explain how you can set the default search scope of Advanced Search Webpart. By default, advanced search webpart searches content based on ‘All Sites’ search scope which is usually scoped to multiple site collections. I personally feel it’s not a good idea to have your (advanced) search webpart configured to search in many site collections ‘by default’. Probably, most of the times you wouldnt want your users to view content in other site collections. So, to enable users to search content only in the current site you can create a custom search scope that scopes only to the current site. You can easily create a search scope at the site collection level by going to ‘Site Settings -> Search Settings’ from the root site in your site collection. It’s a very simple two step process so i will not cover that in this blog.

Now, to set the default search scope for Advanced search webpart, follow these steps –

  • Edit the advanced search webpart in the browser and get the ‘Properties’ xml. Look for it under ‘Properties’ section in the webpart chrome.
  • Modify all the <ResultType> and add the search scope name which you want to set as default. It should look someting like shown below –

<ResultType DisplayName=”All Results” Name=”default”>
<KeywordQuery>scope=”YourCustomScope“</KeywordQuery>
</ResultType>
<ResultType DisplayName=”Documents” Name=”documents”>
<KeywordQuery>scope=”YourCustomScope”</KeywordQuery>
</ResultType>
<ResultType DisplayName=”Word Documents” Name=”worddocuments”>
<KeywordQuery>FileExtension=”doc” OR FileExtension=”docx” And scope=”YourCustomScope”</KeywordQuery>
</ResultType>
<ResultType DisplayName=”Excel Documents” Name=”exceldocuments”>
<KeywordQuery>FileExtension=”xls” OR FileExtension=”xlsx” And scope=”YourCustomScope”</KeywordQuery>
</ResultType>
<ResultType DisplayName=”PowerPoint Presentations” Name=”presentations”>
<KeywordQuery>FileExtension=”ppt” OR FileExtension=”pptx” And scope=”YourCustomScope”</KeywordQuery>
</ResultType>

Save and close the page !

Leave a Comment

Your email address will not be published. Required fields are marked *