Hi drunken monkey, just wondering if you can point me in the right direction? I'd like to boost the relevancy score of results if they are within specified dates, say a boost of 5 for within the last week, 4 for the last month, 3 for the last year etc.

Any pointers greatly appreciated.

Comments

tanc’s picture

I've tried creating a data processor but I can't seem to get it to work on date fields. I thought that I might be able to create a processor that adds a boost score to the results based on date but after playing with the code it looks like data processors might not be able to do that. I can add a boost score on preprocess but that would get stored in the index which isn't useful as this needs to be dynamically adjusted. So still stumped.

tanc’s picture

A little more information about doing this directly on a solr search query: http://wiki.apache.org/solr/SolrRelevancyFAQ#How_can_I_boost_the_score_o...
But I have no idea how to implement this using search_api.

tanc’s picture

Status: Active » Fixed

Based on the notes in a great blog post I was able to write the following function which adds relevancy score to my results based on date (most recent get higher score):

function mymodule_search_api_solr_query_alter(&$call_args, $query) {
  $call_args['params']['bf'][] = 'recip(abs(ms(NOW/HOUR,ds_publication_date)),4.16e-11,4,.4)';
}

This boosts the most recently posted items in the search results by 10 points scaling down to around 3 points at about a year and slowly reducing after that. As stated in that blog post, using Wolfram Alpha to plot the curve can help in tweaking your results. Mine is here.

I hope this helps someone else out in the same situation.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

inky@inky3d.com’s picture

Issue summary: View changes

Hi tanc

I'm trying to add this to a site and needing a few extra directions.

Did you place the function in your template.php, or in a separate module, as the original blog post suggests?

Is the "ds_publication_date" specific to each site and/or solr index?
I've tried changing it to just "publication_date" and it comes up with no search results.

Any guidance would be appreciated,

thanks

inky@inky3d.com’s picture

If anyone else comes across this, I managed to get this to work with Search API 7.x-1.13 and Search API Solr 7.x-1.6

The changes I made to tancs original script in #3 were based on the hooks outlined in search_api_solr.api.php

/**
 * Implements hook_search_api_solr_query_alter().
 */
function mymodule_search_api_solr_query_alter(array &$call_args, SearchApiQueryInterface $query) {
  $call_args['params']['bf'] = 'recip(ms(NOW/HOUR,ds_created),4.16e-11,4,.4)^10';
}

To find the field name specific to your solr index, look in the solr files under yoursolrindex/data/index/ and open one of the .fnm files. I didn't have access to the Solr schema browser, so had to dig through the index to find it.