see on GitHub

Querying : Boosting

Indexing in RavenDB is built upon the Lucene engine that provides a boosting term mechanism. This feature introduces the relevance level of matching documents based on the terms found.

Each search term can be associated with a boost factor that influences the final search results. The higher the boost factor, the more relevant the term will be.

You can improve your searching mechanism and provide users with much more accurate results.

Examples

IList<User> users = session
    .Query<User>()
    .Search(x => x.Hobbies, "I love sport", boost: 10)
    .Search(x => x.Hobbies, "but also like reading books", boost: 5)
    .ToList();
IList<User> users = session
    .Advanced
    .DocumentQuery<User>()
    .WhereStartsWith(x => x.Name, "G")
    .Boost(10)
    .WhereStartsWith(x => x.Name, "A")
    .Boost(5)
    .ToList();
from Users
where boost(search(Hobbies, 'I love sport'), 10) or boost(search(Hobbies, 'but also like reading books'), 5)

This search will promote users who do sports before book readers and they will be placed at the top of the results list.


IList<User> users = session
    .Advanced
    .DocumentQuery<User>()
    .WhereStartsWith(x => x.Name, "G")
    .Boost(10)
    .WhereStartsWith(x => x.Name, "A")
    .Boost(5)
    .ToList();
from Users
where boost(startsWith(Name, 'G'), 10) or boost(startsWith(Name, 'A'), 5)

This shows users which name starts with letter 'G' or 'A'. Results which starts with 'G' go first.

Remarks

Information

Boosting is also available at the index definition level. You can read more about it here.