Index: drupalorg_search/drupalorg_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drupalorg/drupalorg_search/drupalorg_search.module,v
retrieving revision 1.14
diff -u -r1.14 drupalorg_search.module
--- drupalorg_search/drupalorg_search.module	6 Jul 2010 23:45:27 -0000	1.14
+++ drupalorg_search/drupalorg_search.module	30 Jul 2010 21:43:43 -0000
@@ -24,14 +24,14 @@
     if (isset($node->taxonomy[DRUPALORG_MODULE_TID])) {
       return 'module';
     }
-    else if (isset($node->taxonomy[DRUPALORG_THEME_TID])) {
+    elseif (isset($node->taxonomy[DRUPALORG_THEME_TID])) {
       return 'theme';
     }
   }
-  else if ($node->type == 'book') {
+  elseif ($node->type == 'book') {
     return 'documentation';
   }
-  else if ($node->type == 'project_issue' || $node->type == 'forum') {
+  elseif ($node->type == 'project_issue' || $node->type == 'forum') {
     return 'forum-issues';
   }
 }
@@ -105,11 +105,15 @@
  */
 function drupalorg_search_block($op = 'list', $delta = 0, $edit = array()) {
   if ($op == 'list') {
-    $blocks = array();
-
-    $blocks['search_box'] = array(
-      'info' => t('Drupalorg Search: Search box'),
-      'cache' => BLOCK_NO_CACHE,
+    $blocks = array(
+      'search_box' => array(
+        'info' => t('Drupalorg Search: Search box'),
+        'cache' => BLOCK_NO_CACHE,
+      ),
+      'drupalorg_search_browse' => array(
+        'info' => t('Drupalorg Search: Project Browsing'),
+        'cache' => BLOCK_NO_CACHE,
+      ),
     );
 
     // Add the facet blocks.
@@ -120,7 +124,7 @@
     }
     return $blocks;
   }
-  else if ($op == 'view' && $delta == 'search_box') {
+  elseif ($op == 'view' && $delta == 'search_box') {
     if (apachesolr_has_searched() && ($response = apachesolr_static_response_cache()) && ($query = apachesolr_current_query())) {
       $querystring = $query->get_query_basic();
     }
@@ -137,7 +141,7 @@
       );
     }
   }
-  else if ($op == 'view' && $delta == 'meta_type') {
+  elseif ($op == 'view' && $delta == 'meta_type') {
     if (apachesolr_has_searched() && ($response = apachesolr_static_response_cache()) && ($query = apachesolr_current_query())) {
       $entries = array();
       $total = 0;
@@ -174,6 +178,44 @@
       }
     }
   }
+  elseif ($op == 'view' && $delta == 'drupalorg_search_browse' && apachesolr_has_searched() && ($response = apachesolr_static_response_cache()) && ($query = apachesolr_current_query())) {    
+    $parent_term = drupalorg_search_get_parent_term($response);
+    if (!isset($parent_term)) {
+      // This facet cannot process generic queries.
+      return;
+    }
+    return array(
+      'subject' => t('Browse @project_type', array('@project_type' => $parent_term->name)),
+      'content' => drupal_get_form('project_solr_browse_projects_form', $parent_term),
+    );
+  }
+}
+
+function drupalorg_search_get_parent_term($response) {
+  // Find the parent term for this query.
+  $project_vid = _project_get_vid();
+  if (isset($response->responseHeader->params->fq)) {
+    foreach ($response->responseHeader->params->fq as $query_snippet) {
+      if (preg_match('/^{!tag=meta_type}ss_meta_type:(.*)$/', $query_snippet, $matches)) {
+        $tid = NULL;
+        $meta_type = trim($matches[1]);
+
+        if ($meta_type == 'theme') {
+          $tid = DRUPALORG_THEME_TID;
+        } 
+        elseif($meta_type == 'module') {
+          $tid = DRUPALORG_MODULE_TID;
+        }
+        if (isset($tid)) {
+          $term = taxonomy_get_term($tid);
+          if ($term->vid == $project_vid) {
+            return $term;
+            break;
+          }
+        }
+      }
+    }
+  }
 }
 
 /**
@@ -213,6 +255,45 @@
 }
 
 /**
+ * Implementation of hook_form_FORM_ID_alter().
+ */
+function drupalorg_search_form_project_solr_browse_projects_form_alter(&$form, &$form_state) {
+  if (arg(0) == 'search' && arg(1) == 'apachesolr_search') {
+    // If we're on the search page, we want to alter the project browse form
+    // so that it sends us back to the search page and includes ss_meta_type
+    $form['path'] = array(
+      '#type' => 'value',
+      '#value' => 'search/apachesolr_search/' . arg(2),
+    );    
+    $form['#submit'][] = 'drupalorg_search_project_solr_browse_project_form_submit';
+
+    // We default the text to our url value so that we don't get errors
+    // when attempting to sort by relevancy. Make the access false, so that
+    // the values aren't visible and we don't have 2 search forms.
+    $form['text']['#default_value'] = arg(2);
+    $form['text']['#access'] = FALSE;
+  }
+}
+
+/**
+ * Submit handler for inserting ss_meta_type values into the path for 
+ * project_solr_browse_project_form submissions from the search page.
+ */
+function drupalorg_search_project_solr_browse_project_form_submit(&$form, &$form_state) {
+  // Project_solr_browse_projects_form_submit handles most of the other elements
+  // but it doesn't handle ss_meta_type, so we handle that here.
+  $query = apachesolr_current_query();
+  $filters = explode(' ', $form_state['redirect'][1]['filters']);
+  foreach($query->get_filters() as $filter) {
+    if ($filter['#name'] == 'ss_meta_type') {
+      $filters[] = $filter['#query']; 
+    }
+  }
+  $form_state['redirect'][1]['filters'] = implode(' ', $filters);
+  unset($form_state['redirect'][1]['keys']);
+}
+
+/**
  * Form callback; display a search form in a block.
  */
 function drupalorg_search_block_form(&$form_state, $querystring) {
