Hi,

I noticed that sorting options are regarding only Relevancy, title, node type, author and date.

I need to sort also for a cck date field. How can I do it?

Comments

Anonymous’s picture

I'm also interested in this functionality as well as being able to sort by Taxonomy terms

alex72rm’s picture

Status: Active » Closed (works as designed)

I solved by myself.

I've defined a custom module where I set up an hook.

function apache_solr_custom_apachesolr_prepare_query(&$query, &$params) {  
  
  //Remove sorts
  $query->remove_available_sort('type'); 
  $query->remove_available_sort('sort_name'); 
  $query->remove_available_sort('created'); 
 
  //Rename/Reorder sorts
  $query->remove_available_sort('score');
  $query->set_available_sort('score', array('title' => t('Relevancy'), 'default' => 'desc')); 
  $query->remove_available_sort('sort_title');
  $query->set_available_sort('sort_title', array('title' => t('Title'), 'default' => 'asc'));
  $query->set_available_sort('tds_cck_field_publication_date', array('title' => t('Publication date'), 'default' => 'desc'));  
}

and 'tds_cck_field_publication_date' is the ID, taken from URL when I go over a link on cck date facet block (previously defined).

Anonymous’s picture

Issue tags: +taxonomy

Would this approach work for Taxonomy as well? I have several Taxonomy vocabularies that I'd like to sort the results by.

alex72rm’s picture

I tried that too, but unfortunately the only variable available now is the term's tid, that being a number does not allow the alphabetical sort you need. We need the help of someone who knows more about ...

acbramley’s picture

I've tried doing this in drupal 7 with no luck either. under admin/reports/apachesolr it says my date field is in the index (dm_24_field_date_publication) but when I add an available sort with:

    $query->setAvailableSort('dm_24_field_date_publication', array(
      'title' => t('Published date'),
      'default' => 'asc',
    ));

I get "The Apache Solr search engine is not available. Please contact your site administrator." when trying to sort by it. I've also tried adding the field to the index using a similar approach as http://drupalconnect.com/blog/steve/creating-custom-sorts-apache-solr but still no luck.