Mugo Web main content.

Boosting specific fields in Solr to favor exact matches

By: Benjamin Kroll | February 24, 2026 | eZ Find and Solr

Many of our solutions use Solr as a search engine. We find that Solr can provide powerful and flexible search experiences, customizable through its configuration. In this case, we resolved an issue where very generic names of important pieces of content were making them harder to find.

The problem

A publisher has an important book called "Being and Time". They expect the book to appear at the top of the site’s search results with the search phrase "Being and Time". However, it appears towards the bottom of the first page instead. What happened?

The explanation

(Note: this is general and may not apply to all Solr configurations)

In this case, we are using Solr version 4.x operating as the search solution within our ReaderBound product. This fix can be applied to other versions of Solr.

The search solution builds Solr’s index data based on the CMS’s content object attribute data, among other things. The storage and handling of that data is determined by Solr’s schema.

To provide “good” results Solr processes search input by tokenizing and stemming as well as removing parts that are too common. The end result is “Being and Time” becomes two tokens, “be” and “time”.

Scoring is applied based on where and how often these tokens appear in an indexed document.
As you can imagine, those two tokens appear in plenty of other documents.

Adding to the issue for this publisher was a “boost” applied based on the content object’s publish date, favouring newer content. In this case, that date reflects the book’s publication date and the edition of “Being and Time” was published back in 2010.

Using Solr’s debugQuery parameter can help understand how a search term is handled and scored. The Solr query screen has built-in support for it.

The solution

To allow exact title searches to yield better results, an additional boost was applied to target matches in a single field "attr_title_s". This is a string type field that is not tokenized or stemmed.

The boost was set using eZ Find’s boost_functions fetch parameter.

$search_hash = hash(     'query', $search_text     , 'boost_functions', hash('mfunctions', array( concat( 'if(termfreq(attr_title_s,', $search_text|solr_escape(), '), 5, 0 ) )' ) )

As a result, the book now appears as the first result.

The boost function specifically is this:

if(termfreq(attr_title_s,'<SEARCH_TEXT_HERE>'),5,0)

Further explanation— what this boost does

Documents whose title contains the exact token '<SEARCH_TEXT_HERE>' get a 5× multiplier.

termfreq(field, term)

Returns the number of occurrences of the literal term in the field (0 if absent).

if(condition, 5, 0)

If the term occurs at least once in "attr_title_s" it returns 5, otherwise 0.