In the series "How to change the way search results are displayed in SharePoint Server 2013" I showed you how you can customize the way your search results are displayed by adding custom icons and properties.
When it comes to displaying search results, design and content are indeed very important, however there is one thing that often trumps them both: the order in which search results are displayed.Think of your own behavior when looking at search results. How often do you click to view the second page of search results? Personally, my answer to that question is “hardly ever.” So, when displaying search results, it is important that the results that your users are looking for are displayed as high up in the search results list as possible. In this blog post, I’ll show you how you can use a query rule to change the order in which search results are displayed. To demonstrate how query rules work, I'll use an example from an internal Microsoft Search Center.In this blog post, we’ll learn:
What was the problem again?As you know, Microsoft publishes thousands of articles across TechNet, MSDN and office.com. To assist in the publishing process, we use several SharePoint lists. Each item in a list represents an article or a media file. To make it easy to find information about a particular list item, we created a Search Center that searches across these lists.The following screenshot shows the default order in which search results were displayed in our Search Center. Notice that search results for articles and images were displayed in a mixed order.
When users search for something in this Search Center, they are usually looking for information about an article. So, to make it easier for users to find information about articles, I wanted to change the order of the search results so that images would be displayed at the bottom. To do this, I had to create a query rule.
When using query rules: define before you assign
A query rule is pretty much what the name implies: a rule that can be applied to queries. But before you start to assign rules to your queries, you should define what you want the query rule to do. Basically, you have to define two things: a condition and an action. Simply put, this comes down to defining the following: “when X (condition), do Y (action)”. In my scenario, I knew the action part: Display list items that represent images at the bottom of the search results list. In our lists, we use the site column Content Type to differentiate between the type of articles or media types a list item represents. For example, all images have the value “Art” for Content Type.
Based on this, I was able to define the condition part, so that my final definition was:
When list items are of Content Type “Art”, display these at the end of the search results list. So, with the definition in place, I could start to create the query rule that would make this happen.
How to create a query rule that will change the order in which search results are displayed
Depending on your permission level, you can create a query rule on three levels:
To save space, I will only show you how to create a query rule as a Site collection administrator.
I wanted to change the order of search result, so in the Build Your Query dialog box, I selected the SORTING tab.
From the Sort by menu, I selected Rank.
From the Dynamic ordering section, I selected Add dynamic ordering rule.
From the Change ranking when menu, I selected Manual condition.
Remember, I wanted list items of Content Type Art to be displayed at the end of the search results list. So, in the Manual condition field, I entered ContentType:Art, and selected Demote to bottom.
Now, before we move on, let me break down what I entered:
Put it together, and it matches the definition I had specified: When list items are of Content Type “Art”, display these at the end of the search results list.
Your newly created query rule will be listed on the Manage Query Rules page.
In my scenario, I could see that the Demote Art query rule had been created.
When I now entered a search in the Search Center, I could see that articles were displayed at the top of the search results list, while images were displayed at the bottom. Nice!
How do I know that the query rule’s been applied?
In my scenario, I could easily verify that the query rule I created was being applied. However, if you are uncertain about whether or not your query rule is being applied, the Search Results Web Part will be able to give you an answer.
To verify that a query rule is being applied, here’s what you should do:
In my scenario, I could verify that my query rule was working by looking at the following:
Think twice before applying a query rule
Even though this was a relatively simple query rule, you saw that the effect was quite noticeable. So a word of warning: even though query rules are great for changing the order in which search results are displayed, you should think carefully before applying too many of them. The effects can be quite large, and the more complex query rules you have, the more performance resources each query will require. But, if used with caution, you can make the users of your Search Center very happy customers.
Changing the ranking of search results in SharePoint 2013Manage query rules in SharePoint Server 2013