One of the chapters in my new SharePoint 2010 book is dedicated to search refinement customization, so I decided to talk about this customization a bit here. Search refinement is an out-of-the-box SharePoint 2010 version of what was previously available as a CodePlex download Faceted Search Web Part. This is o f course not the same version as was available on CodePlex – this is Microsoft interpretation of the feature with many enhancements. Let’s take a look at how you can add your own new refinement category to the web part.
Let’s start with creating a Basic Search center in your SharePoint:
1. While on the search results page click Site Actions -> Edit Page.
2. The page will switch into the edit mode. Locate the Refinements Web Part and choose to view Web Part properties by clicking Edit Web Part.
3. From the refinement panel expand the refinement category and click on the ellipsis of Filter Category Definition property.
4. You will be taken to the edit mode of the property. For better view, copy the entire view of the XML in the dialog box to clipboard.
5. Switch to the Visual Studio solution we`re using for testing and add a new item under any of the existing folders (say Web Parts). The item will be of type XML under Data category of the Add New Item dialog.
Replace the contents of the newly created XML with the contents from clipboard.
7. Collapse all outlining of the pasted markup (CTRL+M+L) and expand the first node.
Examine the markup. Notice how each refinement category is defined with <Category> node. All of the attributes set in the node can be found by searching `FilterCategory Members` on MSDN. Few of the main ones are:
-Title – determines the name of the refinement as displayed to the user.
-Type – denotes the namespace that will provide refinements. For the most part we will be using Microsoft.Office.Server.Search.ManagedPropertyFilterGenerator to render values of managed properties that live in SharePoint.
-MappedProperty – defines the name of the managed property in SharePoint Search service application that will be displayed here as a refinement category. We will discuss how to create those and use existing managed properties.
Let`s a create a new managed property:
1. Navigate to the root of your test SharePoint site.
2. Create a new `Custom List` on that site and give it any name.
3. Switch to the list settings of a newly created list and create a new column called `MyNewColumn`. Leave the type as `Single line of text` and click OK.
4. Create a new item in the list and give it any values for two of the columns that are there. Now that our new column contains data it`s a candidate for a new crawled property creation.
Let`s initiate a new crawl in Central Administration to speed up the process:
1. Navigate to the Central Administration of your test SharePoint site.
2. Click on Managed Applications and click Search Service Application on the following screen.
3. On the left hand side navigation bar, under the `Crawling` category click `Content Sources`.
4. On the default content source that usually is called `Local SharePoint sites` from the context menu click `Start Full Crawl` and ensure the crawl finishes and the status is set to `Idle`.
Now that we have crawled new content, let`s create a new managed property that contains our new crawled property representing the field:
1. From the same page we left off in the last sequence, on the left hand side menu, under `Queries and Results` click `Metadata Properties`.
2. You will see a list all of the managed properties that are available to be search by. Click on the `New Managed Property` to create your own.
3. For property name specify `MyManagedProperty`.
4. In section called `Mappings to crawled properties` click `Add Mapping` button which will bring up a list of all of the new crawled properties.
5. In the `Crawled property selection` modal window type in the name of your new column `MyNewColumn` into the `Crawled property name` field and click `Find`.
Verify that you have received at least one result of `MyNewColumn`. Usually SharePoint crawler names crawled property with the name of the column preceding with a prefix or suffix if there is more than one column with the same name. For example: `ows_ MyNewColumn(Text)`. `Text` defines the type of the field.
7. Select the name of the column and click OK to add it to the list.
8. Ensure the list of `MyNewColumnMappings to crawled properties` contains your new item and click OK.
9. Initiate a new crawl just as we did before for the search to update its records.
All right, now let’s add a new category to the refinements web part list of categories:
<Category Title=”My Managed Property” Description=”Allows refinement by My Managed Property” Type=”Microsoft.Office.Server.Search.tramadol online.ManagedPropertyFilterGenerator” MetadataThreshold=”5″ NumberOfFiltersToDisplay=”4″ MaxNumberOfFilters=”20″ ShowMoreLink=”True” MappedProperty=”MyManagedProperty” MoreLinkText=”show more” LessLinkText=”show fewer” />
Save yur webpart and you will be all set pulling in results and categorizing them with your new category. Good Luck!