Index: drupalorg/drupalorg-download.tpl.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drupalorg/drupalorg/drupalorg-download.tpl.php,v
retrieving revision 1.13
diff -u -p -u -p -r1.13 drupalorg-download.tpl.php
--- drupalorg/drupalorg-download.tpl.php	7 Aug 2010 17:52:28 -0000	1.13
+++ drupalorg/drupalorg-download.tpl.php	10 Aug 2010 18:14:13 -0000
@@ -43,7 +43,7 @@
   
 <div class="grid-12 alpha omega drupal-modules">
   <h2>Drupal Modules</h2>
-  <p>Show only modules for Drupal version <a href="http://drupal.org/node/428292">DROPDOWN</a></p>
+  <?php print $version_form; ?>
 </div>
 
 <div class="grid-12 alpha omega drupal-modules-facets">
Index: drupalorg_search/drupalorg_search.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drupalorg/drupalorg_search/drupalorg_search.info,v
retrieving revision 1.2
diff -u -p -u -p -r1.2 drupalorg_search.info
--- drupalorg_search/drupalorg_search.info	12 Feb 2009 12:47:24 -0000	1.2
+++ drupalorg_search/drupalorg_search.info	10 Aug 2010 18:14:13 -0000
@@ -3,4 +3,6 @@ name = Drupal.org search
 description = Drupal.org search customizations
 package = Drupal.org
 dependencies[] = apachesolr_search
+dependencies[] = project_release
+dependencies[] = project_solr
 core = 6.x
Index: drupalorg_search/drupalorg_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drupalorg/drupalorg_search/drupalorg_search.module,v
retrieving revision 1.21
diff -u -p -u -p -r1.21 drupalorg_search.module
--- drupalorg_search/drupalorg_search.module	9 Aug 2010 19:07:07 -0000	1.21
+++ drupalorg_search/drupalorg_search.module	10 Aug 2010 18:14:13 -0000
@@ -216,7 +216,7 @@ function drupalorg_search_block_view($de
         }
         return array(
           'subject' => t('Browse @project_type', array('@project_type' => $project_type_term->name)),
-          'content' => drupal_get_form('project_solr_browse_projects_form', $project_type_term),
+          'content' => drupal_get_form('project_solr_browse_projects_form', $project_type_term, 'search/apachesolr_search/' . arg(2)),
         );
       }
       break;
@@ -278,12 +278,6 @@ function drupalorg_search_search_theme_f
  */
 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
@@ -348,7 +342,9 @@ function drupalorg_search_block_form_sub
 function drupalorg_search_execute_base_query() {
   // Build a simple query.
   $base_path = 'project/modules';
-  $query = apachesolr_drupal_query('', '', '', $base_path);
+  
+  $filters = isset($_GET['filters']) ? $_GET['filters'] : '';  
+  $query = apachesolr_drupal_query('', $filters, '', $base_path);  
 
   $params = array(
     // The fields to return.
@@ -359,13 +355,15 @@ function drupalorg_search_execute_base_q
     // We need to be able to facet on the project vid value
     // so we can pull project categories.
     'facet.field' => array(
+      'type',
       'im_vid_' . _project_get_vid(),
+      'im_project_release_api_tids',
     ),
-    // Additional criterias.
-    'fq' => array(
-      'type:project_project',
-      'im_vid_' . _project_get_vid() . ':' . DRUPALORG_MODULE_TID,
-    ),
+    // Filters are set below via explicit calls to add_filter() rather than 
+    // here in the $params array. This is because any filters passed to 
+    // apachesolr_drupal_query() will override filters set via the $params
+    // array during the prepare_query() invocation.
+    'fq' => array(),
     'facet' => 'true',
     'facet.mincount' => 1,
     'facet.sort' => 'true',
@@ -373,6 +371,22 @@ function drupalorg_search_execute_base_q
 
   apachesolr_search_add_facet_params($params, $query);
 
+  // Allow modules to alter the query prior to statically caching it.
+  // This can e.g. be used to add available sorts.
+  foreach (module_implements('apachesolr_prepare_query') as $module) {
+    $function_name = $module . '_apachesolr_prepare_query';
+    $function_name($query, $params, 'drupalorg_search_execute_base_query');
+  }
+
+  // We add our fields after the prepare_query() because prepare_query()
+  // generates a call to parse_filters() which destroys anything that
+  // does not get passed into the query on construction.
+  // We explicitly filter the blocks to only show projects with the module tid
+  // associated. These values are not passed in the url, so we add them here
+  // ourselves to ensure we only get the content we want.
+  $query->add_filter('type', 'project_project');
+  $query->add_filter('im_vid_' . _project_get_vid(), DRUPALORG_MODULE_TID);
+
   // Cache the built query. Since all the built queries go through
   // this process, all the hook_invocations will happen later.
   apachesolr_current_query($query);
@@ -405,6 +419,8 @@ function drupalorg_search_preprocess_dru
   foreach ($facets as $delta => $module) {
     $variables[$delta] = drupalorg_block_render($module, $delta);
   }
+
+  $variables['version_form'] = drupal_get_form('drupalorg_search_version_form', 'download');
 }
 
 /**
@@ -451,3 +467,52 @@ function drupalorg_search_get_project_ty
     }
   }
 }
+
+/**
+ * This generates a form containing version selection and a submit button.
+ * 
+ * Generate a form with a version selection to allow filtering page content
+ * based on the drupal version. Also includes path to allow the form to 
+ * potentially submit to other urls if desired.
+ * 
+ * @param string $path
+ *   The base path to which the version form will redirect.
+ */
+function drupalorg_search_version_form(&$form_state, $path) {
+  $query = apachesolr_current_query();
+
+  $form = array();
+
+  // Add version select field to our form.
+  $form['drupal_core'] = project_solr_get_api_version_field($query, t('Show only modules for Drupal version'));
+
+  $form['path'] = array(
+    '#type' => 'value',
+    '#value' => $path,
+  );
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Search'),
+  );
+  return $form;
+}
+
+/**
+ * Create a query with the right version filter and redirect to the right page.
+ * 
+ * Create a new query, add any version filtering if it was selected in the
+ * form, and redirect back to the relevant page with the appropriate filter
+ * string.
+ */
+function drupalorg_search_version_form_submit($form, &$form_state) {
+  // We create a new query with our base path so that we don't need to remove
+  // any existing drupal_core selection, and so that the implict type and 
+  // module tid filters don't end up in the url string.
+  $query = apachesolr_drupal_query('', '', '', $form_state['values']['path']);
+
+  if (!empty($form_state['values']['drupal_core'])) {
+    $query->add_filter(variable_get('project_solr_project_release_api_tids_alias', 'api_version'), $form_state['values']['drupal_core']);
+  }
+
+  $form_state['redirect'] = array($query->get_path(), $query->get_url_queryvalues());
+}
