Friday, November 19, 2010

Add Custom Category to Search Refinement Panel

Goal: Display a custom Category(Facet) called Classification in the SharePoint 2010 Search Refinment Panel.



Initial Steps: Configure your custom column as Managed Property in Central Admin Search Settings. Only Managed Proprites can be displayed under Refinement Panel.

I will not discuss how to create Managed Property in this blog, but focus on Refinement Panel.

Next Steps: You need to edit the Web Part and configure its XML to display the custom Category.

MSND provides description of the XML syntax:
http://msdn.microsoft.com/en-us/library/ff625183.aspx

The above link is not sufficent and there are few additional things you need to know.

Use Default Configuration: The Web Part has a propety "Use Default Configuration" which you need to uncheck.

Unless you uncheck, you Custom XML wont be applied, and a lot of teams miss this setting.



Filter Category Definition: This is the XML input for the Refinement Panel Web Part. I create a XML file in Visual Studio and use the same for editing.

You need to add your custom Category. I added as following to the XML:

<Category Title="Classification" Description="Document Classification" Type="Microsoft.Office.Server.Search.WebControls.ManagedPropertyFilterGenerator" MetadataThreshold="1" NumberOfFiltersToDisplay="4" MaxNumberOfFilters="20" SortBy="Frequency" SortByForMoreFilters="Name" SortDirection="Descending" SortDirectionForMoreFilters="Ascending" ShowMoreLink="True" MappedProperty="classification" MoreLinkText="show more" LessLinkText="show fewer" />

While most of the properties are self explantory and described in above MSDN article, I need to highlight a few.


MappedProperty: specifies Name of managed property. It is case sensitive and seemed to accept only lower case only. Though I called my managed property "Classification" with caps C, I had to set it to "classification" with lower c to make it work.

MetadataThreshhold: Specifies the minimum number of times the property should be present in Search Results to be considered important to be display.

I had very few docs in my dev environment, and my Custom Category will randomly show up. I have now set it to 1 and it displays as expected.

Enable Data View Caching: Performance Optimization option in web part, I had to uncheck it for my changes to be reflected. I have now checked it again and works fine.

Hope this helps others to save time in configuring the web part.

5 comments:

Anonymous said...

Thank you for this blog entry, I was getting hung up on the case of the Mapped Property being an issue until I found out that it has to be lower case!!!

Vinay Bhatia said...

@Anonymous: Glad to know it helped you..took me some time to figure it out

Anonymous said...

Maybe you may want to put a facebook icon to your site. Just bookmarked the url, however I must complete this by hand. Just my suggestion.

mayank said...

Thanks for the post. By changing the MProperty to lower case its not throwing an exception anymore but now I am getting this in Core results webpart "Property doesn't exist or is used in a manner inconsistent with schema settings."
Any Suggestions?

Anonymous said...

thank you