Index: solr/project_solr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/solr/project_solr.module,v
retrieving revision 1.76
diff -u -p -r1.76 project_solr.module
--- solr/project_solr.module	16 Aug 2010 21:28:25 -0000	1.76
+++ solr/project_solr.module	16 Aug 2010 22:44:43 -0000
@@ -87,6 +87,40 @@ function project_solr_reindex_projects($
 //----------------------------------------
 
 /**
+ * Implementation of hook_apachesolr_sort_links_alter().
+ * 
+ * Removes all of the project-specific sorts that should not be part of the sort
+ * by block from apachesolr. If we are filtering by project, then we leave the
+ * primary project-specific sorts in place; otherwise, we remove all project-
+ * specific sorts.
+ * 
+ * @param array &$sort_links
+ *   An array of sort links keyed by the name of the sort.
+ * 
+ * @see apachesolr_block
+ */
+function project_solr_apachesolr_sort_links_alter(&$sort_links) {
+  // By default, we only want to suppress all project sorts from the display 
+  // since they are relevant only to project searches.
+  $suppress_only = FALSE;
+
+  // We take our existing query and check to see if we are filtering to projects
+  // only. If we are, then, we only suppress the sorts that should always be
+  // suppressed (sorts that  are release specific).
+  $query = apachesolr_current_query();
+  $type = $query->get_filters('type');
+  if (is_array($type[0]) && $type[0]['#value'] == 'project_project') {
+    $suppress_only = TRUE;
+  }
+
+  // Remove all of the sorts that should not be displayed.
+  $sorts = project_solr_get_sorts($suppress_only);
+  foreach (array_keys($sorts) as $name) {
+    unset($sort_links[$name]);
+  }
+}
+
+/**
  * Implementation of hook_apachesolr_facets().
  */
 function project_solr_apachesolr_facets() {
@@ -801,18 +835,46 @@ function project_sort_freetext_submit($f
  *   An existing query object to add sorts into.
  */
 function project_solr_add_sorts(&$query) {
+  // Retrieve all project sorts.
+  $sorts = project_solr_get_sorts();
+  // Add all of the project sorts to the query object so that we can sort
+  // results by any of them.
+  foreach ($sorts as $key => $sort) {
+    $query->set_available_sort($key, $sort);
+  }
+}
+
+/**
+ * Return all of the sorts supported by the project module.
+ * 
+ * Return all of the sorts supported by the project module. Can return an entire
+ * array of both primary and secondary sorts or just a set of sorts that should
+ * regularly be suppressed.
+ * 
+ * @param bool $suppress_only
+ *   If FALSE, returns all sorts for the project module. If TRUE,
+ */
+function project_solr_get_sorts($suppress_only = FALSE) {
+  $sorts = array('display' => array(), 'suppress' => array());
   if (module_exists('project_release')) {
-    $query->set_available_sort('ds_project_latest_release', array('title' => t('Last release'), 'default' => 'desc'));
-    $query->set_available_sort('ds_project_latest_activity', array('title' => t('Recent activity'), 'default' => 'desc'));
+    $sorts['display']['ds_project_latest_release'] = array('title' => t('Last release'), 'default' => 'desc');
+    $sorts['display']['ds_project_latest_activity'] = array('title' => t('Recent activity'), 'default' => 'desc');
     $active_terms = project_release_compatibility_list();
     foreach ($active_terms as $tid => $term_name) {
-      $query->set_available_sort('ds_project_latest_release_' . $tid, array('title' => t('Last release'), 'default' => 'desc'));
-      $query->set_available_sort('ds_project_latest_activity_' . $tid, array('title' => t('Recent activity'), 'default' => 'desc'));
+      $sorts['suppress']['ds_project_latest_release_' . $tid] = array('title' => t('Last release'), 'default' => 'desc');
+      $sorts['suppress']['ds_project_latest_activity_' . $tid] = array('title' => t('Recent activity'), 'default' => 'desc');
     }
   }
   if (module_exists('project_usage')) {
-    $query->set_available_sort('sis_project_release_usage', array('title' => t('Usage statistics'), 'default' => 'desc'));
+    $sorts['display']['sis_project_release_usage'] = array('title' => t('Usage statistics'), 'default' => 'desc');
+  }
+  if ($suppress_only) {
+    $sorts = $sorts['suppress'];
+  }
+  else {
+    $sorts = array_merge($sorts['display'], $sorts['suppress']);
   }
+  return $sorts;
 }
 
 //----------------------------------------
