
Search relevance is something that everyone should understand but only a few pay enough attention to. In this blog post, my goal is to demonstrate the art of sorting search results without creating rocket-science-complex custom ranking models.
There are several options, though, which are worth to be aware of. Some of them are even easy-to-implement, so you can get an instant boost to your results’ relevance. Let’s check it out the most powerful operators that is called: XRANK.
Sorting search results by a single property
In some cases, you need the search results ordered by a single property. For example, in the “Latest documents” result set the documents might be ordered by the last modified date, in a descending order.
Or in a search-driven site directory, the sites are ordered alphabetically.
Ordering the search results by a single property is easy, both on-prem and online.
To do this on a specific page, follow these steps:
- Go to you search center, and open the search page for Edit.
- Select the Search Results Web Part, and edit its properties.
- Click on “Change Query”.
- Select “Sorting” in the top navigation.
- Click on Sort by / Select property, then select LastModifiedTime.
- Select Descending.
- Click OK, and save your page.
Please note, that the Managed Property you want to sort your results by, has to be sortable.
It’s also possible to change the default sorting for a whole Result Source. For example, you might be interested in seeing your invoices always ordered by time, in descending order, regardless of which page they are returned as results on.
In this case, what you have to do is to create a Query Rule first, applied to the proper Result Source:
- Go to your site or site collection settings, and open Search Query Rules.
- Select the proper Result Source.
- Click on “New Query Rule”.
- Give your new Query Rule a name: All invoices.
- Under Context, click on Remove Condition, as you want to run this Query Rule for each query against this Result Source.
- Under Actions, select Change ranked results by changing the query.
- In the query builder, follow the steps described above (from step 4. Select Sorting…)
- Save your Query Rule.
Using Query Rules and XRANK
Besides ordering the results by one specific Managed Property, Query Rules can do much more.
Let me introduce XRANK to you: The XRANK operator allows dynamic control over ranking. It boosts the dynamic rank of items based on certain term occurrences without changing which items that match the query.
What does it mean in practice?
In the following XRANK expression, for example, in the following KQL expression PDF files get quite a large boost in their dynamic rank value:
{searchboxquery} (fileextension:pdf) XRANK(NB=2.5)
If using this Query Rule with a Documents Result Set, the ranking of PDF files will be improved significantly.
Another way XRANK can be used is to boost content freshness. See Mikael Svenson’s great article about this topic HERE.
Of course, finding the right ranking option and boost value is always a trial-and-error process, until you finally find the one that your users need. Don’t be afraid of try, test, and collect feedback from the users.
Leave a Reply