Skip to main content

Boost Search Results

When making a full-text search with the Search() method then boosting can be applied
to both Query and DocumentQuery.

List<Employee> employees = session
// Make a dynamic full-text search Query on 'Employees' collection
.Query<Employee>()
// This search predicate will use the default boost value of 1
.Search(x => x.Notes, "English")
// * Pass the boost value using the 'boost' parameter
// * This search predicate will use a boost value of 10
.Search(x => x.Notes, "Italian", boost: 10)
.ToList();

// * Results will contain all Employee documents that have
// EITHER 'English' OR 'Italian' in their 'Notes' field (case-insensitive).
//
// * Matching documents that contain 'Italian' will get a HIGHER score
// than those that contain 'English'.
//
// * Unless configured otherwise, the resulting documents will be ordered by their score.

Boost results - when querying with where clause​

When querying with Where clauses (using an OR condition in between) then boosting can be applied
only with DocumentQuery.

List<Company> companies = session.Advanced
// Make a dynamic DocumentQuery on 'Companies' collection
.DocumentQuery<Company>()
// Define a 'Where' condition
.WhereStartsWith(x => x.Name, "O")
// Call 'Boost' to set the boost value of the previous 'Where' predicate
.Boost(10)
// Call 'OrElse' so that OR operator will be used between statements
.OrElse()
.WhereStartsWith(x => x.Name, "P")
.Boost(50)
.OrElse()
.WhereEndsWith(x => x.Name, "OP")
.Boost(90)
.ToList();

// * Results will contain all Company documents that either
// (start-with 'O') OR (start-with 'P') OR (end-with 'OP') in their 'Name' field (case-insensitive).
//
// * Matching documents that end-with 'OP' will get the HIGHEST scores.
// Matching documents that start-with 'O' will get the LOWEST scores.
//
// * Unless configured otherwise, the resulting documents will be ordered by their score.

Boost a WhereExists() condition with Corax​

In RavenDB 7.2.6 and later, when using the Corax search engine, a boosted WhereExists() condition (exists() in RQL) contributes 1 multiplied by the query boost, rather than a relevance score calculated from the field's values.

For example, .WhereExists(x => x.Fax).Boost(3) (boost(exists(Fax), 3) in RQL) contributes 3 once per matching document, before any index-entry boost is applied.

The WhereStartsWith() and WhereEndsWith() conditions in the example above use relevance-based scoring.
Learn more in Corax: Scoring.

In this article