You cannot underestimate the importance of boosting your relevancy searches. As you can see below in the code snippet, applying a boost to your query is relatively easy. The boost method itself takes a double, which indicates how much boost you wish to apply to that condition. This ultimately affects the the sort order when the query is returned from the search provider layer. One thing to keep in mind when doing a relevancy search is that you do not want to apply sorting to the search query.

The code below is searching on tours. It is saying that if you pass a NeoId, apply a boost of a factor of 5. If what you searched is contained in the tour’s title, apply a boost of a factor of 4. It goes through these different conditions until it searches without a boost on the basic tour content (summary, description among a few other things).

string keyword = contentParameter.Values[0].ToLower();

Expression<Func<TourResultItem, bool>> innerPredicate = PredicateBuilder.True<TourResultItem>();
innerPredicate = innerPredicate.And(i => i.NeoId.Equals(keyword).Boost(4f)
	|| i.TitleWords.Contains(keyword).Boost(3f)
	|| i.CountryNamesLowercase.Contains(keyword).Boost(2f)
	|| i.ContinentNamesLowercase.Contains(keyword).Boost(2f)
	|| i.ColletteContent.Contains(keyword));


Happy Coding!

3 thoughts on “Boosting

  1. Mihaela

    Does this actually work? I have tried boosting on a wildcard search i.e. using Contains,in Sitecore 7 initial release with a Lucene index, and the boost did not work. I even raised it with Sitecore Support and they confirmed boosting only works on exact match searches i.e using Equals.
    Are things different with Solr?


    1. tbraga1983 Post author

      I’m not sure with Lucene but with Solr it works like a charm. It might depend on how your fields are set in the configuration, check the returnType attribute, mine are either set to string or stringCollection.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s