3

Is there the ability through contrib module or hooks to modify how the apache solr sort block sorts queries?

Currently, it seems it supports these queries out of the box:

  • Relevancy
  • Title
  • Author
  • Date

What i would like to have is to remove Author, Add a field to sort title from a-z and z-a. Is that possible?

2 Answers 2

5

You can find all info with examples here: http://drupal.org/node/715276

<?php
function MYMODULE_apachesolr_query_prepare(DrupalSolrQueryInterface &$query, &$caller) {
  $query->addParam('fl', 'some_field_image');
  $query->addParam('fl', 'some_field_date');
  //Remove sorts
  $query->remove_available_sort('sort_label');
  $query->remove_available_sort('bundle');
  $query->remove_available_sort('sort_name');
  //Rename sorts
  $query->remove_available_sort('score');
  $query->set_available_sort('score', array('title' => t('Relevance'), 'default' => 'desc'));
  $query->remove_available_sort('ds_created');
  $query->set_available_sort('ds_created', array('title' => t('Latest'), 'default' => 'desc'));
 }
?>
1
  • 1
    Welcome to Drupal Answers! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Link-only answers are not considered proper answers on Stack Exchange websites
    – Clive
    Commented Apr 15, 2013 at 11:19
1

There is a module Apachesolr Sort that provides an UI to configure apachesolr sort block. From module page:

  • Removal of a sort by field
  • Weights for the sort by fields
  • Neat integration with the apachesolr modules.
  • Adds a block that gives you a select block to sort your results on.

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.