diff --git a/ProjectSolrQuery.php b/ProjectSolrQuery.php
deleted file mode 100644
index b102c93..0000000
--- a/ProjectSolrQuery.php
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-
-include_once drupal_get_path('module', 'apachesolr') .'/Solr_Base_Query.php';
-
-class ProjectSolrQuery extends Solr_Base_Query {
-  /**
-   * Return the search path.
-   */
-  public function get_path() {
-    return $this->base_path;
-  }
-}
diff --git a/project_solr.module b/project_solr.module
index 75f0a10..b4fd526 100644
--- a/project_solr.module
+++ b/project_solr.module
@@ -155,9 +155,11 @@ function project_solr_apachesolr_index_document_build_node(ApacheSolrDocument $d
       INNER JOIN {term_node} tn ON n.nid = tn.nid
       INNER JOIN {term_data} td ON tn.tid = td.tid
       WHERE prn.pid = %d AND td.vid = %d';
+    
     $term_query = db_query($raw_term_query, $node->nid, _project_release_get_api_vid());
     while ($term = db_fetch_object($term_query)) {
       $document->setMultiValue('im_project_release_api_tids', $term->tid);
+      
       $raw_latest_activity_query = "SELECT f.timestamp, prn.rebuild
         FROM {node} n
         INNER JOIN {project_release_nodes} prn ON n.nid = prn.nid
@@ -313,6 +315,9 @@ function project_solr_browse_summary_page() {
   return theme('item_list', $items);
 }
 
+/*
+ * @todo : This page should become a search page
+ */
 function project_solr_browse_page($term_name) {
   try {
     $output = '';
@@ -337,10 +342,13 @@ function project_solr_browse_page($term_name) {
     if ((!isset($sort) || !preg_match('/^([a-z0-9_]+ (asc|desc)(,)?)+$/i', $sort)) && empty($text_query)) {
       $sort = variable_get('project_solr_default_sort', 'sort_title asc');
     }
+    // This is the object that does the communication with the solr server.
+    $env_id = apachesolr_default_environment();
 
-    include_once drupal_get_path('module', 'project_solr') .'/ProjectSolrQuery.php';
+    $solr = new DrupalApacheSolrService();
+    $solr = apachesolr_get_solr($env_id);
 
-    $query = new ProjectSolrQuery(apachesolr_get_solr(), $text_query, $filters, $sort, 'project/' . drupal_strtolower($project_type->name));
+    $query = new SolrBaseQuery($solr, $text_query, $filters, $sort, 'project/' . drupal_strtolower($project_type->name));
     if (is_null($query)) {
       throw new Exception(t('Could not construct a Solr query.'));
     }
@@ -361,20 +369,18 @@ function project_solr_browse_page($term_name) {
     $page = isset($_GET['page']) ? $_GET['page'] : 0;
     $params['start'] = $page * $params['rows'];
 
-    // This is the object that does the communication with the solr server.
-    $solr = apachesolr_get_solr();
 
     // We add add_filter() parameters here to include all the constant
     // filters for the query -- project nodes of the given top-level type that
     // have releases (if project_release is enabled).
     // We use add_filter() rather than $params['fq'] so that our filters
     // are correctly passed to anything that uses our cached query.
-    $query->add_filter('type', 'project_project');
-    $query->add_filter('im_vid_'. _project_get_vid(), $project_type->tid);
+    $query->addFilter('type', 'project_project');
+    $query->addFilter('im_vid_'. _project_get_vid(), $project_type->tid);
     // We can only filter on bs_project_has_releases for just official projects,
     // since sandbox projects can never have releases.
     if (module_exists('project_release') && $query->has_filter('bs_project_sandbox', '0')) {
-      $query->add_filter('bs_project_has_releases', '1');
+      $query->addFilter('bs_project_has_releases', '1');
     }
 
     // Allow modules to alter the query prior to statically caching it.
@@ -386,29 +392,27 @@ function project_solr_browse_page($term_name) {
 
     // Cache the built query. Since all the built queries go through
     // this process, all the hook_invocations will happen later.
-    apachesolr_current_query($query);
+    apachesolr_current_query($env_id, $query);
 
-    // This hook allows modules to modify the query and params objects.
-    apachesolr_modify_query($query, $params, 'project_solr');
     if (!$query) {
       return array();
     }
 
     // Force sort to be by the corresponding core compatibility if filtered.
-    $sort = $query->get_solrsort();
+    $sort = $query->getSolrSort();
     if (in_array($sort['#name'], array('ds_project_latest_release', 'ds_project_latest_activity'))
-      && ($api_filters = $query->get_filters('im_project_release_api_tids'))) {
+      && ($api_filters = $query->getFilters('im_project_release_api_tids'))) {
       $first_filter = reset($api_filters);
       $params['sort'] = $sort['#name'] .'_'. $first_filter['#value'] .'  '. $sort['#direction'];
     }
 
-    $response = $solr->search($query->get_query_basic(), $params['start'], $params['rows'], $params);
+    $response = $solr->search($query->getQueryBasic(), $params);
 
     // The response is cached so that it is accessible to the blocks and anything
     // else that needs it beyond the initial search.
     $total = $response->response->numFound;
     apachesolr_static_response_cache($response);
-    apachesolr_has_searched(TRUE);
+    apachesolr_has_searched(apachesolr_default_environment(), TRUE);
 
     // Set breadcrumb.
     $breadcrumb = menu_get_active_breadcrumb();
@@ -480,7 +484,7 @@ function project_solr_block_info() {
     ),
   );
   if (module_exists('project_release')) {
-    $blocks['project_solr_compability'] = array(
+    $blocks['project_solr_compatibility'] = array(
       'info' => t('Project Solr: core compatibility'),
       'cache' => BLOCK_CACHE_PER_PAGE,
     );
@@ -500,13 +504,14 @@ function project_solr_block_info() {
  */
 function project_solr_block_view($delta) {
   // None of these blocks make sense unless there's been a solr search.
-  if (!apachesolr_has_searched()) {
+  $env_id = apachesolr_default_environment();
+  if (!apachesolr_has_searched($env_id)) {
     return;
   }
 
-  $response = apachesolr_static_response_cache();
-  $query = apachesolr_current_query();
-
+  $query = apachesolr_current_query($env_id);
+  $response = apachesolr_static_response_cache($query->getSearcher());
+  
   switch ($delta) {
     case 'project_solr_categories':
       // Find the parent term for this query.
@@ -534,7 +539,7 @@ function project_solr_block_view($delta) {
 
       // Get the terms at the current depth.
       $current_tid = $project_type->tid;
-      foreach ($query->get_filters() as $filter) {
+      foreach ($query->getFilters() as $filter) {
         if ($filter['#name'] == 'tid') {
           $current_tid = $filter['#value'];
           break;
@@ -547,7 +552,7 @@ function project_solr_block_view($delta) {
       }
 
       foreach ($response->facet_counts->facet_fields->$facet as $tid => $count) {
-        $active = $query->has_filter('tid', $tid);
+        $active = $query->hasFilter('tid', $tid);
         if (!isset($current_level_terms[$tid]) && (!$active || $tid != $current_tid)) {
           continue;
         }
@@ -555,16 +560,16 @@ function project_solr_block_view($delta) {
         $term = taxonomy_get_term($tid);
         $new_query = clone $query;
 
-        $path = $new_query->get_path();
+        $path = $new_query->getPath();
         $options = array();
         if ($active) {
-          $new_query->remove_filter('tid', $term->tid);
-          $options['query'] = $new_query->get_url_queryvalues();
+          $new_query->removeFilter('tid', $term->tid);
+          $options['query'] = $new_query->getSolrsortUrlQuery();
           $link = theme('apachesolr_unclick_link', $term->name, $path, $options);
         }
         else {
-          $new_query->add_filter('tid', $term->tid);
-          $options['query'] = $new_query->get_url_queryvalues();
+          $new_query->addFilter('tid', $term->tid);
+          $options['query'] = $new_query->getSolrsortUrlQuery();
           $link = theme('apachesolr_facet_link', $term->name, $path, $options, $count, $active, $response->numFound);
         }
         $countsort = $count == 0 ? '' : 1 / $count;
@@ -595,7 +600,7 @@ function project_solr_block_view($delta) {
       }
       break;
 
-    case 'project_solr_compability':
+    case 'project_solr_compatibility':
       if (module_exists('project_release')) {
         $facet = 'im_project_release_api_tids';
         $terms = array();
@@ -612,13 +617,13 @@ function project_solr_block_view($delta) {
 
         foreach ($active_terms as $tid => $term_name) {
           if (!empty($active_term_counts[$tid])) {
-            $active = $query->has_filter('im_project_release_api_tids', $tid);
+            $active = $query->hasFilter('im_project_release_api_tids', $tid);
             $new_query = clone $query;
-            $path = $new_query->get_path();
-            $new_query->remove_filter('im_project_release_api_tids', $term->tid);
+            $path = $new_query->getPath();
+            $new_query->removeFilter('im_project_release_api_tids', $term->tid);
             $options = array();
             if ($active) {
-              $options['query'] = $new_query->get_url_queryvalues();
+              $options['query'] = $new_query->getSolrsortUrlQuery();
               $link = theme('apachesolr_unclick_link', $term_name, $path, $options);
             }
             else {
@@ -641,8 +646,8 @@ function project_solr_block_view($delta) {
 
     case 'project_solr_text':
       return array(
-        'subject' => t('Search @project_type', array('@project_type' => $query->get_query_basic())),
-        'content' => drupal_get_form('project_sort_freetext', $query->get_path()),
+        'subject' => t('Search @project_type', array('@project_type' => $query->getParam('q'))),
+        'content' => drupal_get_form('project_sort_freetext', $query->getPath()),
       );
 
   }
@@ -653,14 +658,14 @@ function project_solr_block_view($delta) {
  */
 function project_solr_browse_projects_form(&$form_state, $project_type, $path) {
   drupal_add_css(drupal_get_path('module', 'project_solr') .'/project_solr.css');
-  $response = apachesolr_static_response_cache();
-  $query = apachesolr_current_query();
-
-  $text = $query->get_keys();
+  $env_id = apachesolr_default_environment();
+  $query = apachesolr_current_query($env_id);
+  $response = apachesolr_static_response_cache($query->getSearcher());
+  $text = $query->getParam('q');
 
   // Get the terms at the current depth.
   $current_tid = '';
-  foreach ($query->get_filters() as $field) {
+  foreach ($query->getFilters() as $field) {
     if ($field['#name'] == 'tid') {
       $current_tid = $field['#value'];
       break;
@@ -693,7 +698,7 @@ function project_solr_browse_projects_form(&$form_state, $project_type, $path) {
     if ($project_type->tid == variable_get('project_type_associated_tid_' . $vid, NULL)) {
       $selected = array();
       // Extract selected values from our filters.
-      foreach ($query->get_filters() as $filter) {
+      foreach ($query->getFilters() as $filter) {
         if ($filter['#name'] == 'im_vid_'. $vid) {
           $selected[] = $filter['#value'];
         }
@@ -798,15 +803,16 @@ function project_solr_get_solrsort_field($label = NULL) {
 }
 
 function project_solr_browse_projects_form_submit($form, &$form_state) {
-  include_once drupal_get_path('module', 'project_solr') .'/ProjectSolrQuery.php';
-  $query = new ProjectSolrQuery(apachesolr_get_solr(), $form_state['values']['text'], '', '', $form_state['values']['path']);
+  $env_id = apachesolr_default_environment($env_id);
+  $solr = apachesolr_get_solr($env_id);
+  $query = new SolrBaseQuery($solr, $form_state['values']['text'], '', '', $form_state['values']['path']);
 
   if (!empty($form_state['values']['tid'])) {
-    $query->add_filter('tid', $form_state['values']['tid']);
+    $query->addFilter('tid', $form_state['values']['tid']);
   }
 
   if (!empty($form_state['values']['api_version'])) {
-    $query->add_filter(variable_get('project_solr_project_release_api_tids_alias', 'api_version'), $form_state['values']['api_version']);
+    $query->addFilter(variable_get('project_solr_project_release_api_tids_alias', 'api_version'), $form_state['values']['api_version']);
   }
 
   // Loop over all project-related vocabularies and create filters
@@ -816,7 +822,7 @@ function project_solr_browse_projects_form_submit($form, &$form_state) {
     $values = array_filter($form_state['values']['im_vid_' . $vid]);
     if (!empty($values)) {
       foreach($values as $value) {
-        $query->add_filter('im_vid_'. $vid, $value);
+        $query->addFilter('im_vid_'. $vid, $value);
       }
     }
   }
@@ -834,22 +840,22 @@ function project_solr_browse_projects_form_submit($form, &$form_state) {
   }
 
   // Add the project sandbox filter.
-  $query->add_filter('bs_project_sandbox', $form_state['values']['bs_project_sandbox']);
+  $query->addFilter('bs_project_sandbox', $form_state['values']['bs_project_sandbox']);
 
   // Add all project-specific sorts so that the sort set in set_solrsort() will
   // work as intended.
   project_solr_add_sorts($query, variable_get('project_solr_project_release_api_tids_alias', 'api_version'));
-  $query->set_solrsort($solrsort[0], $solrsort[1]);
+  $query->setSolrSort($solrsort[0], $solrsort[1]);
   $query_values = $query->get_url_queryvalues();
   if (!empty($form_state['values']['text'])) {
-    $query_values['text'] = $query->get_query_basic();
+    $query_values['text'] = $query->getParams('q');
   }
   // By setting this as an array, FAPI is going to hand it to drupal_goto().
   // drupal_goto() itself doesn't care about the keys, but we define them here
   // to make the code more self-documenting, especially if people are trying
   // to alter this form (e.g. in drupalorg_search.module).
   $form_state['redirect'] = array(
-    'path' => $query->get_path(),
+    'path' => $query->getPath(),
     'query' => $query_values,
   );
 }
@@ -893,8 +899,10 @@ function project_sort_freetext(&$form_state, $base_path) {
  * Submit handler for project_sort_freetext().
  */
 function project_sort_freetext_submit($form, &$form_state) {
-  if ($query = apachesolr_current_query()) {
-    $queryvalues = $query->get_url_queryvalues();
+  $env_id = apachesolr_default_environment($env_id);
+  if ($query = apachesolr_current_query($env_id)) {
+    $query = new SolrBaseQuery();
+    $queryvalues = $query->getSolrsortUrlQuery();
   }
   else {
     $queryvalues = array();
@@ -920,8 +928,9 @@ function project_sort_freetext_submit($form, &$form_state) {
  *   An ApacheSolr $query object.
  */
 function project_solr_run_project_query($base_path, $filters = array()) {
+  $env_id = apachesolr_default_environment();
   $filterstring = isset($_GET['filters']) ? $_GET['filters'] : '';
-  $query = apachesolr_drupal_query('', $filterstring, '', $base_path);
+  $query = apachesolr_drupal_query('project_solr_run_project_query', array('fq' => $filterstring), '', $base_path);
 
   // Figure out all the fields we need to use as facets.
   // First handle all the implicit filters we're going to add ourselves.
@@ -942,23 +951,18 @@ function project_solr_run_project_query($base_path, $filters = array()) {
     'start' => 0,
     'rows' => 5,  // TODO: make this configurable.
     'facet.field' => $facet_fields,
-    // 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',
     'sort' => variable_get('project_solr_default_sort', 'sort_title asc'),
   );
 
-  apachesolr_search_add_facet_params($params, $query);
+  $query->addParams($params);
 
   // 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';
+  foreach (module_implements('apachesolr_query_prepare') as $module) {
+    $function_name = $module . '_apachesolr_query_prepare';
     $function_name($query, $params, 'project_solr_run_project_query');
   }
 
@@ -968,26 +972,26 @@ function project_solr_run_project_query($base_path, $filters = array()) {
   // We explicitly filter the blocks to only show projects with the right
   // category. 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->addFilter('type', 'project_project');
 
   if (!empty($filters)) {
     foreach ($filters as $filter) {
-      $query->add_filter($filter['key'], $filter['value']);
+      $query->addFilter($filter['key'], $filter['value']);
     }
   }
 
   // Cache the built query. Since all the built queries go through
   // this process, all the hook_invocations will happen later.
-  apachesolr_current_query($query);
+  apachesolr_current_query($env_id, $query);
 
   // This hook allows modules to modify the query and params objects.
-  apachesolr_modify_query($query, $params, 'project_solr_run_project_query');
+  //apachesolr_modify_query($query, $params, 'project_solr_run_project_query');
 
-  $solr = apachesolr_get_solr();
-  $response = $solr->search($query->get_query_basic(), $params['start'], $params['rows'], $params);
+  $solr = apachesolr_get_solr($env_id);
+  $response = $solr->search($query, $params);
 
-  apachesolr_static_response_cache($response);
-  apachesolr_has_searched(TRUE);
+  apachesolr_static_response_cache($query->getSearcher(), $response);
+  apachesolr_has_searched($env_id, TRUE);
 
   return $query;
 }
@@ -1009,7 +1013,7 @@ function project_solr_get_api_version_field($query, $label = NULL) {
     $terms = array();
     $active_terms = project_release_compatibility_list();
     foreach ($active_terms as $tid => $term_name) {
-      $active = $query->has_filter('im_project_release_api_tids', $tid);
+      $active = $query->hasFilter('im_project_release_api_tids', $tid);
       if ($active) {
         $current_tid = $tid;
       }
@@ -1055,15 +1059,15 @@ function project_solr_get_api_version_field($query, $label = NULL) {
 function project_solr_add_sorts(&$query, $api_filter = 'im_project_release_api_tids') {
   if (module_exists('project_release')) {
     // Pull any existing filter on version.
-    $versions = $query->get_filters($api_filter);
+    $versions = $query->getFilters($api_filter);
     $tids = array();
     foreach ($versions as $version) {
       $tids[] = $version['#value'];
     }
     // If we have no version selected, only present the base sorts.
     if (empty($tids)) {
-      $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('Last build'), 'default' => 'desc'));
+      $query->setAvailableSort('ds_project_latest_release', array('title' => t('Last release'), 'default' => 'desc'));
+      $query->setAvailableSort('ds_project_latest_activity', array('title' => t('Last build'), 'default' => 'desc'));
     }
     else {
       // If we have versions selected, only present sorts for our selected
@@ -1072,14 +1076,14 @@ function project_solr_add_sorts(&$query, $api_filter = 'im_project_release_api_t
       $active_terms = project_release_compatibility_list();
       foreach ($tids as $tid) {
         if (isset($active_terms[$tid])) {
-          $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('Last build'), 'default' => 'desc'));
+          $query->setAvailableSort('ds_project_latest_release_' . $tid, array('title' => t('Last release'), 'default' => 'desc'));
+          $query->setAvailableSort('ds_project_latest_activity_' . $tid, array('title' => t('Last build'), 'default' => 'desc'));
         }
       }
     }
   }
   if (module_exists('project_usage')) {
-    $query->set_available_sort('sis_project_release_usage', array('title' => t('Most installed'), 'default' => 'desc'));
+    $query->setAvailableSort('sis_project_release_usage', array('title' => t('Most installed'), 'default' => 'desc'));
   }
 }
 
@@ -1173,15 +1177,15 @@ function project_solr_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']);
+  $query = apachesolr_drupal_query('project_solr_version_form_submit', '', '', $form_state['values']['path']);
 
   $version_alias = variable_get('project_solr_project_release_api_tids_alias', 'api_version');
 
   if (!empty($form_state['values'][$version_alias])) {
-    $query->add_filter($version_alias, $form_state['values'][$version_alias]);
+    $query->addFilter($version_alias, $form_state['values'][$version_alias]);
   }
 
-  $form_state['redirect'] = array($query->get_path(), $query->get_url_queryvalues());
+  $form_state['redirect'] = array($query->getPath(), $query->getSolrsortUrlQuery());
 }
 
 //----------------------------------------
@@ -1272,9 +1276,9 @@ function project_solr_fetch_category_items($project_type, $category_term) {
   $base_path = 'project/' . drupal_strtolower($project_type->name);
   $query = project_solr_run_project_query($base_path, $filters);
 
-  $query_values = $query->get_url_queryvalues();
+  $query_values = $query->getSolrsortUrlQuery();
 
-  $response = apachesolr_static_response_cache();
+  $response = apachesolr_static_response_cache($query->getSearcher());
 
   $items = array();
   if ($response->response->numFound > 0) {
@@ -1286,7 +1290,7 @@ function project_solr_fetch_category_items($project_type, $category_term) {
   if ($items) {
     // Add the "more" link.
     $items[] = array(
-      'data' => l(t('More @category', array('@category' => $category_term->name)), $query->get_path(), array('query' => $query_values)),
+      'data' => l(t('More @category', array('@category' => $category_term->name)), $query->getPath(), array('query' => $query_values)),
       'class' => 'more',
     );
   }
