Monday, June 11, 2012

Modify Languages and Result Types in SharePoint Advanced Search

SharePoint 2010 advanced search window by default let us search by set of languages and result types as below.
























We can customize this set of languages and result types from the properties window of the webpart. If we expand the Properties section of the Advanced Search Box window, we can notice that there are three options:

1.    "Show Properties" checkbox
2.    Properties section label
3.    "Properties" text field


The first two options, the checkbox and properties section label fields display and label the Properties list, the last part of the webpart.

The third option, Properties field is which we going to use for languages and result types customization. As you can see in the small part shown in this text box, it is an XML definition, which will look like as follows.
















Here we can see four primary nodes under the root of the XML:

1.    LangDefs
2.    Languages
3.    PropertyDefs
4.    ResultTypes

First node, LangDefs (Language Definitions) provides a list of all the languages that SharePoint Search supports.

Second node, Languages lists down all the languages shown in the webpart. It should be noted that the LangID parameter from the LangDefs is used as the LangRef in this section.

LangDefs - <LangDef DisplayName="English" LangID="en"/>
Languages - <Language LangRef="en"/>


So if we want to display only the English, French and Spanish languages in the webpart, languages node should look like:

<Languages>
   <Language LangRef="en"/>
   <Language LangRef="fr"/>
   <Language LangRef="es"/>
</Languages>

The languages will be presented in the webpart in the order they listed in above XML node.


Third node in the XML definition, the PropertyDefs are used for the ResultTypes. PropertyDefs represent the standard managed properties used by SharePoint Search. Each PropertyDef provides the actual managed property name, a DisplayName for use in the Property Restrictions dropdown, and a DataType to allow the UI to provide appropriate comparison prompts. If we define our own managed properties in Search, we will need to manually add each property to this list in order to let our users to be able to choose them in the "Add property restrictions" section.

Forth node, the ResultTypes node contains the definitions for the items which appear in Result type dropdown. Each ResultType contains PropertyRef references from the PropertyDefs. Which means if we define our own managed properties in PropertyDefs, we will need to add them to the appropriate ResultTypes as well.

So a customized advanced search window will look like:


No comments: