Blog» Sorting search results by date-based relevance in eZ Find

Sorting search results by date-based relevance in eZ Find

By Peter Keung  | November 19, 2015  |  eZ Publish development tips, Web solutions

The eZ Publish search extension eZ Find offers many sorting parameters for its search results, the most common being by relevance / score, and by date. On large sites, sorting by date can lead to non-relevant results showing up first. What if you want to sort by date and relevance, essentially boosting newer content but still giving you relevant results?

With eZ Find, results can be boosted at index time or at query time. In this case, it makes the most sense to boost the results by date at query time, so that other searches aren't affected by the age of the content.

eZ Find uses the Solr search engine, which has some documentation on date-based boosting. Using the native Solr functionality and eZ Find's boost_functions parameter, we can construct a query such as this:

{def $search_parameters = hash( 'query', $q,
                                                 'offset', $offset,
                                                 'class_id', $classes,
                                                 'limit', $page_limit,
                                                 'boost_functions', hash( 'mfunctions', array( 'recip(ms(NOW/HOUR,meta_published_dt),3.16e-11,1,1 )' ) )
{set $search = fetch( 'ezfind', 'search', $search_parameters )}

"mfunctions" makes the boost multiplicative instead of additive, and "meta_published_dt" is the name of the Solr field that stores the standard object publish date.

With such a query, the standard score for each is multiplied by "1 for very recent documents, 1/2 for documents a year old, 1/3 for documents two years old", and so on, as per the example documentation, with "3.16e-11" representing the inverse of a year in milliseconds. The boost can be applied differently based on different periods, with a boost intensity to suit your site. Here is a useful graph showing how the different settings can be tweaked to adjust the intensity scale.

Join our mailing list for news, events, tips, and tools

Related Blog Posts

Securing eZ Find's Solr installation

When using eZ Publish's eZ Find extension on a public facing site or project -- arguably any project -- it is vital to secure it to prevent unauthorized...

Read more »

Adding data to the eZ Find index with Index Time Plugins

Index time plugins are one of the most important techniques of extending eZ Find functionality; they allow you to control how and what data is indexed....

Read more »


blog comments powered by Disqus

Hi, we're Mugo Web - Nice to meet you!

We're a group of web experts who solve complex web problems.

Learn more about us »



Yes - we can do that.

Many years of experience with complex websites allows us to offer total solutions.

Learn more about what we can do »

We love our clients (and they love us too)

We've solved problems across North America and around the world.

Learn more about what we've done »

We tweet too

Follow us on Twitter for the latest Mugo happenings

mugo twitter page @mugo

© 2008 - 2019 Mugo Web. All rights reserved.