Ranking search results in Kentico

This post shows how you could override search results order.


Recently I received the request from the client to build search results page. This page should be a default search results, where all results are ordered by relevance, except there are items (pages), those should appear always at the top of others results, even if they match search criteria just once.


I started to look for solutions and, at the very beginning, I thought about different types of customization: custom search results web part, overriding built in search functionality, etc. But I was enough lucky to come out with really simple solution, which does not require customization (customization is evil!), and I'd like to share my approach with you.

So I decided to add Search Rank field to the page type(s), which will need to appear on the very topo in the results. I setup zero as a default value for that fields. So all pages of the type will be assigned to zero by default. If we need some particular result to appear at the top, all we need is just specifying any positive number for the fields. Also you can differentiate pages, those appear before all other assigning different Search Rank to them, e.g.: pages with Search Rank equal 1 appears before regular search results; pages with Search Rank equals 5 are more import and appears before pages with Search rank equal 1; Items with Search Rank equal 10 are the most important and appears at the very top of the search results list.

Next step we have to make is including Search Rank field into a search index. This could be done in Page Types application by editing appropriate Page Type Search fields. Just navigate SearchRank field and check Content and Searchable check boxes, save changes.

Now we need to rebuild search index(es) used by the Smart search results web part on the search results page. So open Smart Search application, navigate appropriate Search Index and click rebuild.

The step in this process is setting up correct search order for the Smart search results. It should be following:

SearchRank desc, ##SCORE##

Okay, we are done from technical stand point. The only thing we left is content editors' piece, which requires going and populating Search Rank field for needed documents.


So you can see that suggested approach is really simple, easy to implement and does not require customization, which always is a huge advantage. It allows us to combine together Kentico out of the box functionality with requirement specific one in order to meet our goal. I believe that this could be useful in many other scenarion, those are not described in this post.

If you have any question on the approach, or want to share your experience solving similar problems - just leave your comment under the post. I really appreciate any feedback.