Index: drupalorg_search/drupalorg_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drupalorg/drupalorg_search/drupalorg_search.module,v
retrieving revision 1.17
diff -u -p -r1.17 drupalorg_search.module
--- drupalorg_search/drupalorg_search.module	6 Aug 2010 08:43:42 -0000	1.17
+++ drupalorg_search/drupalorg_search.module	6 Aug 2010 08:51:08 -0000
@@ -67,15 +67,18 @@ function drupalorg_search_apachesolr_upd
  * Returns an array keyed by block delta.
  */
 function drupalorg_search_apachesolr_facets() {
-  $facets = array();
-
-  $facets['meta_type'] = array(
-    'info' => t('Drupalorg Search: Filter by meta type'),
-    'facet_field' => '{!ex=meta_type}ss_meta_type',
-    'exclude_filter' => '',
+  return array(
+    'meta_type' => array(
+      'info' => t('Drupalorg Search: Filter by meta type'),
+      'facet_field' => '{!ex=meta_type}ss_meta_type',
+      'exclude_filter' => '',
+    ),
+    'sort_title' => array(
+      'info' => t('New modules'),
+      'facet_field' => 'created',
+      'direction' => 'desc',
+    ),
   );
-
-  return $facets;
 }
 
 /**
@@ -326,6 +329,100 @@ function drupalorg_search_block_form_sub
 }
 
 /**
+ * Base query required for creating the download page context for solr-related
+ * blocks. Creates and caches a solr query for use by block elements.
+ */
+function drupalorg_search_execute_base_query() {
+  // Build a simple query.
+  $base_path = 'project/modules';
+  $query = apachesolr_drupal_query('', '', '', $base_path);
+
+  $params = array(
+    // The fields to return.
+    'fl' => 'id,nid,title',
+    'start' => 0,
+    // We don't actually need to return rows.
+    'rows' => 1,
+    // We need to be able to facet on the project vid value
+    // so we can pull project categories.
+    'facet.field' => array(
+      'im_vid_' . _project_get_vid(),
+    ),
+    // Additional criterias.
+    'fq' => array(
+      'type:project_project',
+      'im_vid_' . _project_get_vid() . ':' . DRUPALORG_MODULE_TID,
+    ),
+    'facet' => 'true',
+    'facet.mincount' => 1,
+    'facet.sort' => 'true',
+  );
+
+  apachesolr_search_add_facet_params($params, $query);
+
+  // Cache the built query. Since all the built queries go through
+  // this process, all the hook_invocations will happen later.
+  apachesolr_current_query($query);
+
+  // This hook allows modules to modify the query and params objects.
+  apachesolr_modify_query($query, $params, 'drupalorg_search_execute_base_query');
+
+  $solr = apachesolr_get_solr();
+  $response = $solr->search($query->get_query_basic(), $params['start'], $params['rows'], $params);
+
+  apachesolr_static_response_cache($response);
+  apachesolr_has_searched(TRUE);
+}
+
+function drupalorg_search_load_facet_block($module, $delta, &$variables) {
+  // Load the title, since that can be modified administratively.  
+  $title = db_result(db_query("SELECT title FROM {blocks} WHERE module = '%s' AND delta = '%s')", $module, $delta));
+
+  $block_output = module_invoke($module, 'block', 'view', $delta);
+  foreach ($block_output as $k => $v) {
+    $block->$k = $v;
+  }
+  
+  // Set the module and delta so that the blocks contain
+  // at least the minimum of expected information.
+  $block->module = $module;
+  $block->delta = $delta;
+  
+  if (isset($block->content) && $block->content) {
+    // Override default block title if a custom display title is present.
+    if ($title) {
+      // Check plain here to allow module generated titles to keep any markup.
+      $block->subject = $title == '<none>' ? '' : check_plain($title);
+    }
+    if (!isset($block->subject)) {
+      $block->subject = '';
+    }    
+  }
+  return $block;
+}
+
+function drupalorg_search_preprocess_drupalorg_download(&$variables) {
+  drupalorg_search_execute_base_query();
+  
+  $facets = array(
+    'drupalorg_order_facet:sort_most_installed',
+    'project_solr:project_solr_categories',
+    'drupalorg_order_facet:sort_title',
+  );  
+  // Preprocess the facet blocks.  
+  $line = array();
+  foreach ($facets as $facet) {
+    list($module, $delta) = explode(':', $facet);
+    $block = drupalorg_search_load_facet_block($module, $delta, $variables);
+    $rendered_facet = theme('block', $block);
+    // Since we control what facets we're building, we can just utilize the
+    // delta for the sake of brevity.
+    $variables[$delta] = $rendered_facet;
+  }  
+  
+}
+
+/**
  * Get the taxonomy term for the project type (if any) in a given Solr search.
  *
  * This function loops over all of the active facets in the given Solr query
