Monday 11 March 2013

Customizing the advanced search Webpart adding custom properties

Pre conditions: To add custom properties to the advanced search you need custom properties created in the search engine configuration.
We need to access the page where is the advanced search Webpart as we can see in the image 1.
1_Advanced_Serarch_Webpart
We are editing the Advanced Search Webpart to access the configuration section as we can see in the image 2.
[Image 2]
2_Advanced_Search_Webpart_Configuration_Section
In the configuration section we go to the properties section and we edit it to add our custom properties as we can see in the image 3 we have a text editor to do this task.
[Image 3]
3_Advanced_Search_Editing_Configuration
We must add our custom property in this XML. To add it is better to copy the XML from text editor and copy into a tool to handle documents XML, in this case we are using Visual Studio 2008. In the image 4 we can see the XML edited in Visual Studio.
[Image 4]
4_Xml_Editing_In_VisualStudio
We must add a new node named “PropertyDef” in the section “PropertyDefs”. This node is used to define our property into the schema of the search engine and we must set the following attributes
  • Name: the name of our custom property
  • DataType: the type of our custom property. In this case the value is “text” because when we created this custom property selected “Text” as type.
  • DisplayName: the name that we have want show in the advanced search DropDown.
For example: <PropertyDef Name="CustomProperties1" DataType="text" DisplayName="Custom Properties 1"/>
The second step is to setup the “PropertyDef” added into the other section where we want use. The XML have a node named “ResultTypes” where define a lot of result type, one per type of result that we want use. We must add a node in each section that we want use our property. For example, if we want use our property in “All Results” result type then we need to put the following node:
<PropertyRef Name="CustomProperties1" />
In the image 5 we can see the custom property added to the result type named “All Results”.
[Image 5]
5_Adding_Cutompropery_To_Xml
If we want use our custom property in other result types then we must add the node into the section for the custom result.
When we finish with the configuration we must copy the XML modified and must paste into the text editor where was copied, save the changes in the text editor, save the change in the Webpart property configuration and close the mode edition page. In the image 6 we can see as our custom property is showed into the dropdown list in the advanced search Webpart.
[Image 6]
6_Advanced_Serarch_Configured
Now we can use our custom property to search information crawled by SharePoint Engine Search

No comments:

Post a Comment