
The feature of search refiners has been in SharePoint since the version of 2010. In SharePoint 2013, SharePoint 2016 and Office 365 we have deep refiners, which means each result in the result set is processed, calculated and used when calculating the refiners. I have explained this concept in this blog post earlier.
In SharePoint 2010, we had shallow refiners, which means there was no way to display the item counts at all. At the same time, in FAST Search for SharePoint 2010, we had deep refiner, therefore the items counts were calculated and also displayed by default.
However, in the new versions (2013, 2016, SharePoint Online), we cannot see the item counts on the search refiners by default. Why? – you might ask.
Out-of-the-box search refiners
Let’s start from what we have out-of-the-box. When you open your search center, you find something like this:
As you can see, the default refiners don’t display the items counts.
Why? Don’t we have deep refiners now?
And if we do, how could we change this default behavior?
The truth is this: we do have deep refiners in SharePoint 2013, 2016 and SharePoint Online (this is why the counts can be represented by the sliders of the Modified Date refiner above), but by default the counts are hidden for text refiners.
Search Refinement Panel is a web part in SharePoint. When you edit the page and open the Refinement web part’s properties, you’ll see something like this:
Although there are some very exciting options here, please let me focus on the button “Choose Refiners” for now. Once you click on it, a nice and fancy wizard will be displayed:
Let’s see what we have here.
First, there’s a visual control for selecting the refiners we need on our Search page.
On the left side there’s the list of available refiners (managed properties, that are set to be “refinable“). And on the right side, you can see your current selections. Of course, you can add and remove as well as reorder the refiners here.
When you select a refiner in the list above, you’ll see its configuration in the bottom half of the screen. Things you can configure here:
- Display name
- Display template (see below)
- Sort by
- Sort direction (ASC / DESC)
- Maximum number of refiner values
Search refinement display templates
The Display Template you select above defines how to display the given refiner. If you open the dropdown list, you can see and select the existing templates. Out of the box, you have the following options:
- Refiner Item
- Multi-value Refiner Item
As I said earlier, we do have deep refinement in SharePoint, therefore the item counts are calculated. However, they are hidden, and this behavior is defined in the refinement display templates.
If you want to display the item counts, there are two options:
- You can modify the existing “Refiner Item” display template, OR
- You can create a custom display template.
If you want to change the default behavior for each refiner across all your search pages in a site collection, the first option is what you have to choose. However, let me show you how to create a custom display template, since this is the more complex one. (And after reading and understanding these steps, you will be able to modify the existing display template, too.)
Creating a new refinement display template
If you want to create your own display template, you have two options, again. The first one is, to go to the Design Manager in the site settings menu, and make a copy of the existing “Refinement Item” display template (Filter_Default.html).
The second option is to open the site collection by SharePoint Designer, open the Catalogs / MasterPage / Display Templates / Filters folder, and create a copy of the existing “Refinement Item” display template (Filter_Default.html) which you edit later there.
There are two things to modify here in order to get the item counts displayed:
-
Give a new Title to it, something like this:
<title>Refinement Item with Count</title>
-
Look for the value “ShowCounts”. By default, it’s set to “false”, this is why the item counts are hidden. Change it to “true”:
this.Options = {
ShowClientPeoplePicker: false,
ShowCounts: true
};
Save your file and upload if you use the Design Manager.
Don’t forget to publish the new display template, otherwise other users will get an error after you apply the next steps.
Note: There’s a .js file for each other design templates. Don’t worry about it, this will be automatically created when you upload the HTML. Don’t modify these JavaScript files directly.
Applying the new display template
go back to the Refiner Panel’s properties and open the Display Template dropdown, you’ll see the option “Refiner Item with Count”. Select this for each refiner value you would like to see the counts for – that’s it!
After saving the changes, you will see the item counts for the proper search refiners now. Check-in and publish your page, in order to make the changes visible to other users, too.
If you want to learn further “quick win” configuration tricks, check out my blog post about SharePoint Search Query Rules, too.
Leave a Reply