Custom Refinement Panel for SharePoint 2010 Search based on Departments / Business Unit
Artikel
Scenario
Most of the organizations structure there departments or Business Units into separate site collections. For example all sites related to Human Resource, Finance, Management, Operations etc are grouped into separate site collection under one/multiple farms. Hence, there can be a requirement within search that the search results can be refined based on the department/business unit (site collections) name they are coming from.
Introduction
There is a requirement to enable user to have Business Units (Departments) as a search refiner in the refinement panel for any search made through the search page. The search is done across the farm and there is no metadata stored along with the searched content (list item as a column or document as a document property) to indicate in the refinement panel. This metadata is incorporated using XSL that transform the refinement xml into the refinement panel.
Here we have modified Search Refinement Webpart to get the intended result. Any Search Service can be used in this context.
Two different xml is been modified to get the intended result, which are as follows:
Filter Category Definition
A new category is required to be added to the category xml to the Refinement Panel WebPart. This is our custom category to indicate business unit. Also, ensure to uncheck Use Default Configuration option to enable our custom category to be displayed in refinement panel.
Refinement Panel
Property
Value
Filter Category Definition
Add the following category below the site category:
<Category Title="Department" Description="Which department this document is from" Type="Microsoft.Office.Server.Search .WebControls.ManagedPropertyFilterGenerator" MetadataThreshold="1" NumberOfFiltersToDisplay="4" MaxNumberOfFilters="20" ShowMoreLink="True" MappedProperty="sitename" MoreLinkText="show more" LessLinkText="show fewer" ShowCounts="Count" />
Please ensure that the Category title is the same which you are going to use within XSL file to modify the appearance.
Use Default Configuration
Uncheck the same to enable custom categories to be displayed on refinement panel.
RefinerStyle.xsl
As indicated by above code, webpart also uses the custom XSL Stylesheet in order to display the custom refinement in a specific format that includes the department name along with the number of instance found. This XSL file resides in the root web of the web application at following path:
The above URL is added to XSL Link property of the web part.
XSL Constraint
In order to map the search content to either of the Business Unit, we use the OOB refined managed property sitename which refines based on URL of the search content rolled up to Site Collection.
It is advised to make a copy of OOB XSL file and then make changes to it.
Within XSL we add a condition within <xsl:choose> element of Categories template, in order to provide special handling of the “Department” category.
After, that it only left at Filter template to modify incoming URL value to our custom values. For better implementation a copy of Filter Template is created with name Filter2 which is specific for our custom refinement category
Since the mapping or the metadata about the department of the searched content resides within the xsl file. Any modification is required to be done on every instance of such xsl files (across the farm). The better approach here can be making a web service call (using JavaScript) to the centralized location where a mapping table can be maintained.