- Part 1 – Setting up Managed Metadata Service
- Part 2 – Explaining how to use the Term Store
- Part 3 – Creating a Site Column with managed Metadata (gotchas with List Definitions)
- Part 4 – Search Refiners with Managed Metadata
- Part 5 – Search CAML query with Managed Metadata.
If we open up our Search Centre and query on some data, down the left hand side of the search results is a search refinement panel. This panel gives a breakdown of some metadata found within the search results which allows you to filter it further. If you look at the image below, the default search refiners are Result Type, Site, Author, Modified Date,
and Location. Now location is actually our managed metadata column. However this isn’t a custom one I’ve made, this is created by default by SharePoint. If I had something else in search that was more popular in the results that would have been there instead. So there is no guarantee that will be there for each search.
To get the search to work, you first need to ensure you have put data in a list with the columns you wish to search on, and perform a crawl in Central Administration for any results to show up in search. There are two different types of Search Refiners you can create ManagedPropertyFilterGenerator, or a TaxonomyFilterGenerator.
A ManagedPropertyFilterGenerator can be used with a Managed Metadata Column, however it displays the results as exact matches. What do I mean by that? Well if you remember in my previous blog I had a Term Set called Countries. Inside countries I had a list of Continents, and then countries underneath the Continents.
With a ManagedPropertyFilterGenerator if I selected Europe as my filter, it will only display items that have been tagged with Europe. However, what we are really asking for it any item that is in Europe. Using a TaxonomyFilterGenerator by filtering on Europe we will receive all items tagged with Europe, but also other item that are tagged with countries within Europe, such as United Kingdom, Andorra etc.
Setup for ManagedPropertyFilterGenerator refiner
This wasn’t going to be part of the blog, but as there is a different setup to get your ManagedPropertyFilterGenerator working to the TaxonomyFilterGenerator, I thought I would show you.
- Create your site column, it can be any type of column, but for simplicity use a Choice column. Add some choice values.
- Create a List, and add your choice column to it.
- Then add items to your list. My example is below.
- Now open up Central Administration > Application Management > Manage Service Applications > Search Service Application then click on Content Sources
- On the Manage Content Sources page, click on the right of Local SharePoint Site and select Start Full Crawl
- Once the crawl has completed in the Left Navigation Menu, under Queries and Results click Metadata Properties.
- On the Metadata Property Mappings page click New Managed Property
- Fill in the Property Name: DemoChoice
- Under the Mappings to crawled properties click the button Add Mapping
- In the dialog box, under Crawled property name type DemoSearchChoice. Click Find. Select the crawled property ows_DemoSearchChoice(Text) and click OK.
- Save the Metadata Property Page.
- Now that you have set up the Metadata Property, you need to perform a full crawl again. Follow the steps from earlier to do this.
- Once the full crawl had completed, the way to check if it will work in a search it to navigate to your search center.
- Type in <Name Of Property>:<Value> so for instance my example would be DemoChoice:Red and only the items tagged with Red will appear in my result set.
Set up for TaxonomyFilterGenerator refiner
For the TaxonomyFilterGenerator you don’t actually need to do anything apart from add some data to the list with the column and perform a full search. All managed Metadata columns are added to search Managed properties automatically. Unfortunately I can’t show you in a test, as it’s not quite the same as the Managed Property Generator.
Creating the refiner
- Navigate to your search center results page. Easiest way is to perform a search. Once there edit the page.
- Find the Refinement Panel on the left of the page, and edit the webpart.
- Under the Refinement section there is the Filter Category Defintion, and the Use Default Configuration. The Filter Category Definition is what you will be adding your custom refiner to. However if you do not untick Use Default Configuration it doesn’t matter what you change the Filter Category Definition to, it won’t pick up the change.
If you take a copy of the Filter Category Definition you will be able to see what we are dealing with. It does look quite scary, but all it is, is a collection of <Category> and we just have to create one for our Taxonomy. Details can be found on the Microsoft Site on what can be included in a Category section.
Creating a ManagedPropertyFilterGenerator refiner
First before we get round to doing one for our managed metadata property, we are going to create one for our Choice field we created at the start of this blog. Called DemoChoice.
With notepad or Visual studio copy the following.
<Category Title="CF Demo Choices" Description="Managed Metadata for Blog Demo" Type="Microsoft.Office.Server.Search.WebControls.ManagedPropertyFilterGenerator" MetadataThreshold="1" NumberOfFiltersToDisplay="4" MaxNumberOfFilters="20" SortBy="Frequency" SortByForMoreFilters="Name" SortDirection="Descending" SortDirectionForMoreFilters="Ascending" ShowMoreLink="True" MappedProperty="DemoChoice" MoreLinkText="show more" ShowCounts="Count" LessLinkText="show fewer" />
Let me explain a few things. The Title can be anything you like. MetadataThreshold specifies the number of results that must contain a value to display in the filter generator. I have set this to 1 to ensure that if there is a result, then the refiner will show something. You might want to set this higher in a production environment. The MappedProperty is the value you created during the steps of “Setup for ManagedPropertyFilterGenerator refiner”.
- Assuming you still have the Results page in edit mode, and are editing the Refinement Panel Web Part, take a copy of the above, and insert it after <FilterCategories> and before <Category Title=”Result Type” of the Filter Category Definition.
<?xml version="1.0" encoding="utf-8"?> <FilterCategories> <!--Insert Here--> <Category Title="Result Type"
- Click OK to the WebPart Editor, Save and Close the page from the ribbon.
- In the search, (if you have been following my demo) type item in the search box. In the Search refinement section you will see your ManagedPropertyFilterGenerator at work.
- If you click on any of the links, say Orange the results will re-filter to show you just Items that are tagged with Orange. You might have noticed the number of items next to the value, this is there because I added the XML ShowCounts=”Count”, I could have added Percentage instead.
Creating a TaxonomyFilterGenerator refiner
With notepad or Visual studio copy the following
<Category Title="Location" Description="Taxonomy Managed Metadata for Blog Demo" Type="Microsoft.Office.Server.Search.WebControls.TaxonomyFilterGenerator" MetadataThreshold="1" NumberOfFiltersToDisplay="4" MaxNumberOfFilters="20" SortBy="Frequency" SortByForMoreFilters="Name" SortDirection="Descending" SortDirectionForMoreFilters="Ascending" ShowMoreLink="True" MappedProperty="ows_MetadataFacetInfo" MoreLinkText="show more" LessLinkText="show fewer" />
The difference here is that the Type always points to TaxonomyFilterGenerator.
The MappedProperty always points to ows_MetadataFacetInfo, and the Title points to the name of the Column or Field that the Managed Metadata is mapped to. So in our case Location, (If the field has a space that’s OK but remember it’s the column name.) If you used “Managed Metadata Columns” for your title then it would display all managed metadata columns, not one particular refiner.
- Assuming you still have the Results page in edit mode, and are editing the Refinement Panel Web Part, take a copy of the above, and insert it after <FilterCategories> and before <Category Title=”CF Demo Choices” of the Filter Category Definition.
- Click OK to the WebPart Editor, Save and Close the page from the ribbon.
- In the search, (if you have been following my demo) type item in the search box. In the Search refinement section you will see your TaxonomyFilterGenerator at work.
Above is the picture of my library with the Location data. Below is a Search on “File” which happens to be the title of each document. All 15 items.
Now if I select show more, and then click on Europe. It will show me 5 documents. The one I’ve actually tagged as Europe, and the 4 others that have been tagged to countries that are children of Europe in our Term Set.
In my last blog of this series, I will show you how to perform a CAML query against a Managed Metadata column so that the results will return all child terms as well. Just like we have with the Search Refiner.