0

I'm using Drupal 6.22 with apache solr module for search functionality, specifically using 6.x-1.6 version of solr. I had a date field for my node added to the solr indexing named as ds_myDate in ISO-8601 format (Y-M-DTH:i:sZ) and used it for sorting the search results which worked fine.

Recently I decided to replace the sort with a search boost functionality so that most relevant search results are boosted based on the ds_myDate field. In my custom module's hook_apachesolr_modify_query adding the following code (based on understanding from http://wiki.apache.org/solr/FunctionQuery#Date_Boosting)

$params['bf'][] = "recip(ms(NOW/HOUR,ds_myDate),3.16e-11,1,1)";

to effect the boosting threw 400 error stating Can't use ms() function on non-numeric legacy date field ds_myDate. Hence I tried using an alternative of adding the same in the queryfield instead of boostfield in the same hook as

$params['qf'][] = "recip(ms(NOW/HOUR,ds_myDate),3.16e-11,1,1)";

which got added but did not show any impact on the search results.

As I have very little or no access to the Solr server or its logs I logged the solr query in the search function and in both cases the field was added to the query. In the former case of using boost field (throwing 400 error) the solr search url would return a path like

...qf=tags_inline^5.0&bf=recip(ms(NOW/HOUR,ds_myDate),3.16e-11,1,1)
&bf=recip(rord(created),4,3403,3403)^200.0&fq=...

and in the latter method of using as queryfield would return

...qf=tags_inline^5.0&bf=recip(ms(NOW/HOUR,ds_myDate),3.16e-11,1,1)
    &bf=recip(rord(created),4,3403,3403)^200.0&fq=...

Would be great to know what I'm doing wrong here or how this implementation in Drupal could be done properly since 7 has a hook like hook_apachesolr_query_alter where the date boosting could be done.

1 Answer 1

1

For the legacy date field that the ds_ dynamic field is set to use in the 1.6 version schmea.xml, you can use the rord() function. It's not considered best practice any longer but it works with field types that don't enable using ms(). More information at Solr Wiki. The example query goes like this (copying it here to avoid link rot):

recip(rord(creationDate),1,1000,1000)
1
  • Thank you very much for the suggestion, much appreciated. Guess I have to do the inevitable and add a TrieDate field for the boosting and run a reindex.. Commented May 15, 2013 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.