Notes for calculating boosting factor when using Episerver find boosting filter

Do you ever use Episerver find for searching content in your Episerver site?

Do you ever have requirement about displaying some specific content at the top of search results?

Do you have any problems about the order of search results still wrong even you are using Boosting Filter?

The Boosting Filter allows us could set the boost factor of a search result item when matching the boost filter condition. The score of search result item is calculated by: original score * boost factor.

The thing that I faced to and the thing I am mentioning in this post is using Boosting Filter multiple times without searching term, only within filters.

It is really simple if you have only 1 filter condition for boosting, you only need to use BoostingMatching with a specific boost factor (note that default score is 1 if we do not use search for term, so you should use a value greater that 1 to make sure that those items are on top) do like that:

var searchResult = client.Search<Car>()
    .Filter(x => x.Model.Match("BMW"))
    .BoostMatching(x => x.InStock.Match(true), 2)
    .GetResult();

How do you think about this case with multiple of boosting filters:

var searchResult = client.Search<Car>()
    .Filter(x => x.Model.Match("BMW"))
    .BoostMatching(x => x.InStock.Match(true), 2)
    .BoostMatching(x => x.SalesMargin.GreaterThan(0.2), 3)
    .BoostMatching(x => x.NewModelComingSoon.Match(true), 4)
    .GetResult();

As Episerver documentation then in this case: You can call the method multiple times. If a hit matches several filters, the boost is accumulated.

What does it mean?

It means if you have content A matching the third filter, and you have content B matching the first and second filter then the content B is on top of content A. Because the boost factor of content = 2 + 3 = 5 > 4.

So if you always want show results as same as the score of each filter, not accumulated then you can change the score like that:


var searchResult = client.Search<Car>()
    .Filter(x => x.Model.Match("BMW"))
    .BoostMatching(x => x.InStock.Match(true), 2)
    .BoostMatching(x => x.SalesMargin.GreaterThan(0.2), 3)
    .BoostMatching(x => x.NewModelComingSoon.Match(true), (2 + 3) + 1)
    .GetResult();

It is simple right, making sure the score of next filter = total of previous filters + 1.

You can find the original reference link here https://world.optimizely.com/documentation/Items/Developers-Guide/EPiServer-Find/9/DotNET-Client-API/Searching/Boosting-with-filters/.

Happy coding!