共用方式為


How to change the order in which search results are displayed in SharePoint Server 2013

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.

List item With Content Type:Art

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:

Permission level Where the query rule will be applied
Search service application administrator To all site collections within the farm
Site collection administrator To all sites within a site collection
Site collection owner To a single site

To save space, I will only show you how to create a query rule as a Site collection administrator.

  1. Go to Site Settings --> Search Query Rules.

Search Query Rules on Site Settings page

  1. On the Manage Query Rules page, from the Select a Result Source menu, select the result source to which the query rule should be applied.

Select a esult source to which the query rule should be applied 

  1.  Select New Query Rule.

Select to create a new query rule

  1. On the Add Query Rule page, in the Rule name field, enter a name for the query rule.

    In my scenario, I named the query rule Demote Art.

Enter a name for the query rule

  1. In the Query Conditions section, specify the conditions that will trigger the query rule.

    In my scenario, I wanted the query rule to be triggered every time a user entered a query. In other words, I didn’t want the query rule to be triggered by a specific condition, so I selected Remove Condition.

Remove condition from query rule

  1. In the Actions section, specify what you want the query rule to do when it is triggered.

    In my scenario, I selected Change ranked results by changing the query. This opened a dialog box where I could define what I wanted the query rule to do.

Change ranked results by changing the query

I wanted to change the order of search result, so in the Build Your Query dialog box, I selected the SORTING tab.

SORTING tab in the Build Your Query dialog box

From the Sort by menu, I selected Rank.

Sort by rank

From the Dynamic ordering section, I selected Add dynamic ordering rule.

Add dynamic ordering rule

From the Change ranking when menu, I selected Manual condition.

Change ranking when: 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.

Enter manual condition for query rule

Now, before we move on, let me break down what I entered:

  • ContentType is the managed property that represents the site column Content Type (I explain how you can find managed property names in another blog article).
  • The colon : means “contains”.
  • Art is the managed property value.
  • Demote to bottom is the action that should be taken.

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.

  1. Select OK, and then Save.

 

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.

New query rule listed on the Manage Query Rules page

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:

  1. On your search results page, select to edit the Search Results Web Part.
  2. In the Web Part tool pane, select Change query
  3. In the Build Your Query dialog box, select the TEST tab, and then Show more.

TEST tab in Build Your Query dialog box

 

  1. In the {searchboxquery} field enter a query that you know should cause the query rule to be triggered, and then select Test query.

Verify that Query rule is working

In my scenario, I could verify that my query rule was working by looking at the following:

  1. In the field Applied query rules, the name of my query rule, Demote art, was shown.
  2. In the Query text section, XRANK was applied to ContentType:Art.

 

 

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.

 

 

Additional resources

Changing the ranking of search results in SharePoint 2013
Manage query rules in SharePoint Server 2013

Comments

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    Fantastic series ;)

  • Anonymous
    January 01, 2003
    Hi Mario, Glad you like the series :-) Bella

  • Anonymous
    January 01, 2003
    Hi Uday,

    I'm not sure I quite understand your scenario. Can you explain a bit more what you mean by "manual rules"?

    Bella

  • Anonymous
    January 01, 2003
    Hi Ramesh,

    In your Content Search Web Part, is a custom Sorting being applied?

    Thanks,
    Bella

  • Anonymous
    January 01, 2003
    Hi Frank,

    I suggest that you contact MS Support with your question.

    Bella

  • Anonymous
    January 01, 2003
    Hi Amol,

    I'm sorry, but I'm not quite sure about the answer to your question. I suggest you contact Microsoft Support with your question.

    Thanks,
    Bella

  • Anonymous
    October 09, 2013
    Looks like just what I was after, it promotes/demotes based on content type just as you described. My only issue is it also appears to filter out some results completely. When this rule is active, documents no longer return in the results.

  • Anonymous
    October 09, 2013
    Owesome examples for the query rule.

  • Anonymous
    December 27, 2013
    Pingback from How to change the order in which search results are displayed in SharePoint Server 2013 | Office 365 Singapore for Business - Win-Pro

  • Anonymous
    March 21, 2014
    So useful, thank you!

  • Anonymous
    April 16, 2014
    Hi
    I have configured a search results web part to use manual rules for sorting the results.
    But when I edit the web part and go to the sorting tab on the edit query dialog, the manual conditions are all lost. When I enter the manual conditions again and save the web part, it works fine, but when I edit the web part and the rules are again lost.
    Can you please help?

  • Anonymous
    December 03, 2014
    How to sort in alpha order? I've got a content search web part that was created for me as part of connecting a remote managed catalog. In this specific place I want to have the results come back in alpha order. I would think edit the web-part, click "change query," switch to advanced mode," go to the sorting tab, and select sort by Title or Name. But neither of those properties are there.

  • Anonymous
    March 02, 2015
    The comment has been removed