Adding and Removing Sorts
It's incredibly easy to add more sort links in the solr sort block. Make sure the field you want to sort on is indexed and sortable (you need to add it to your index otherwise). For example, using the existing comment_count field:
Drupal 7
/**
* Implements hook_apachesolr_query_prepare().
*/
function MYMODULE_apachesolr_query_prepare($query) {
$query->setAvailableSort('comment_count', array('title' => t('Most comments'), 'default' => 'desc'));
}
Drupal 6
/**
* Implements hook_apachesolr_prepare_query().
*/
function MYMODULE_apachesolr_prepare_query($query, $caller) {
$query->set_available_sort('comment_count', array('title' => t('Most comments'), 'default' => 'desc'));
}
To remove sorting options in the Apache Solr Sorting block you'll do the same, but call a different method:
Drupal 7
/**
* Implements hook_apachesolr_query_prepare().
*/
function MYMODULE_apachesolr_query_prepare($query) {
$query->removeAvailableSort('created');
$query->removeAvailableSort('sort_name');
}
Drupal 6
/**
* Implements hook_apachesolr_prepare_query().
*/
function MYMODULE_apachesolr_prepare_query($query, $caller) {
$query->remove_available_sort('created');
$query->remove_available_sort('sort_name');
}
As an alternative, you can add an implementation of hook_apachesolr_sort_links_alter(&$sort_links) to a custom module. However, use of the query class methods is preferred.
In the following code both the Author and Date sort links will no longer be displayed (replace MYMODULE with the name of your module).
Drupal 6 (there is no D7 equivalent)
function MYMODULE_apachesolr_sort_links_alter(&$sort_links) {
unset($sort_links['created']);
unset($sort_links['sort_name']);
}
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion