By replacing Drupal's core search with Solr, it's possible to gain very fine control of the results. Not only is Solr very flexble, but the apachesolr module is generous with its hooks. One potential use is boosting the score based on dates, so that recent documents receive a higher relevancy score. We've used this for a ticket calendar to help visitors find upcoming events.

First, look up the name of the field you need in the schema browser (http://localhost:8983/solr/admin/ for a local install). You should be able to locate it based on the machine name of your Drupal field (assuming the index is up-to-date).


Next, drop this hook in a custom module (note this is for Drupal 7). Substitute your field's name in for dm_field_date.

/**   * Implements hook_apachesolr_query_alter().   */  function hook_search_apachesolr_query_alter(DrupalSolrQueryInterface $query) {    $query->addParam('bf', array('freshness' =>      'recip(abs(ms(NOW/HOUR,dm_field_date)),3.16e-11,1,.1)'    ));  }


This function will apply a +10 boost to a document with today's date, tapering off to about +1 after a year. To write your own boost function, consult the Solr Wiki page on FunctionQuery. Note there are no spaces in the function queries! Choosing the constants can feel a bit blind, so visualizing the function on Wolfram Alpha helps (the x-axis is in milliseconds):

advertise with us

Boost your traffic and expand your pool of potential customers

8000 active members

Ready to join Now?

CMS Portal - The free marketplace for submitting Joomla, Drupal, Wordpress, Magento, phpBB, Prestashop, vBulletin, Opencart Templates and more.


Email Newsletters

Make sure you don't miss interesting happenings by joining our newsletter program.
Joomla Templates Free Joomla Templates Virtuemart Templates K2 Templates JoomShopping Templates HikaShop Templates SobiPro Templates OpenCart Themes
Magento Themes Magento Extensions Free Magento Extensions Prestashop Themes Prestashop Modules Magento 2 Themes