Skip to main content

Specify Default Scope for Advanced Search Box Web Part without Using Scope Picker

This led me to investigate the advanced search box web part further and the solution presented itself when I went and viewed the XML for the “Properties” property of the web part. Within the schema there is a node called . It is here that the out of the box configuration specifies the various result types used to bind the result type picker to. Below is the default results type XML for the advanced search box web part.
[Query]FileExtension='ppt'[/Query]
You’ll notice that within the [Query] node that query syntax is being used to filter the search as opposed to keyword syntax. This is important and may explain why you see little to no documentation on how to specify a scope in an advanced search query. In order to specify a scope in query syntax you must enclose the scope restriction in quotes as follows: “scope”=’Your Scope’.

Queries for the “Advanced Search Box” web part, however, are declared in XML. Therefore, in order to enclose the scope restriction in quotes you must escape the quotes in order to make them XML safe. You do this by using the entity reference of ". Other properties do not require this, only the scope property. Below is an example of limiting the out of the box result types for the advanced search box web part to a specific scope.

[Query]FileExtension='ppt' And "scope"='Your Scope'[/Query]

Now that you have declared a scope in your result type query your advanced searches will be limited to the specified scope. This means the scope picker does not need to be displayed as user input is no longer required to limit your results to a particular scope and you can do this without one line of custom code or client side script. I hope you will find this useful and consider using the advanced search box web part for your search applications in SharePoint.

Comments

Popular posts from this blog

How to get SPUser or SPGroup from Person or Group field

You have person or group field in SharePoint list and you want to programmatically get the user or person. The below code to gets SPUser from User or Group field in the list when multiple choice and Groups are not allowed in the field: //get SPUser SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users"); SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString()); SPUser user = userFieldValue.User; This part of code would help you to get SPUser when multiple choice is allowed and groups are not allowed: //Multiple choices are allowed SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users"); SPFieldUserValueCollection userFieldValueCollection = (SPFieldUserValueCollection)userField.GetFieldValue(item["Users"].ToString()); foreach (SPFieldUserValue userFieldValue in userFieldValueCollection) {     Console.WriteLine("     " + userFieldValue.User.LoginName); } And when group

SharePoint publishing page scheduling

In SharePoint 2010 publishing enabled team site collection is not showing schedule button in publish ribbon. Solution: Here is how to enable it  though the UI: Locate the SharePoint Server Web site on which you want to enable content approval and item scheduling. Click  Site Actions , click  Site Settings , and then click  Modify Pages Library Settings . Under  General Settings , click  Versioning Settings . Click  Yes  next to  Content Approval , and then click  OK . Click  Manage item scheduling .   Click to enable the  Enable scheduling of items in this list  check box, and then click  OK .

Changing Content Type Hub URL

Change the Hub URL through powershell by using: Set-SPMetadataServiceApplication -Identity " " -HubURI " " For Ex: Set-SPMetadataServiceApplication -Identity "Managed Metadata Service" -HubURI "http://contenttype.Domain.Com" When you try to do this you get this rather scary message: This is SharePoint telling you that this is a major thing so be careful! Essentially all your content types that you have published out will be removed if they can, and you have to republish all of your content types out again which can cause some issue.