? SolrPhpClient
Index: Solr_Base_Query.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/Solr_Base_Query.php,v
retrieving revision 1.1.4.24
diff -u -p -r1.1.4.24 Solr_Base_Query.php
--- Solr_Base_Query.php	3 Apr 2009 14:37:32 -0000	1.1.4.24
+++ Solr_Base_Query.php	3 Apr 2009 18:01:30 -0000
@@ -1,7 +1,7 @@
 <?php
 // $Id: Solr_Base_Query.php,v 1.1.4.24 2009/04/03 14:37:32 pwolanin Exp $
 
-class Solr_Base_Query {
+class Solr_Base_Query implements Drupal_Solr_Query_Interface {
 
   /**
    * Extract all uses of one named field from a filter string e.g. 'type:book'
@@ -113,7 +113,7 @@ class Solr_Base_Query {
     $this->id = ++self::$idCount;
   }
 
-  function add_field($field, $value) {
+  function add_facet($field, $value) {
     $this->fields[] = array('#name' => $field, '#value' => trim($value));
   }
 
@@ -121,7 +121,7 @@ class Solr_Base_Query {
     return $this->fields;
   }
 
-  public function remove_field($name, $value = NULL) {
+  public function remove_facet($name, $value = NULL) {
     // We can only remove named fields.
     if (empty($name)) {
       return;
@@ -142,7 +142,7 @@ class Solr_Base_Query {
     }
   }
 
-  public function has_field($name, $value) {
+  public function has_facet($name, $value) {
     foreach ($this->fields as $pos => $values) {
       if (!empty($values['#name']) && !empty($values['#value']) && $values['#name'] == $name && $values['#value'] == $value) {
         return TRUE;
@@ -227,6 +227,14 @@ class Solr_Base_Query {
   public function get_query_basic() {
     return $this->rebuild_query();
   }
+  
+  /**
+   * return the search path
+   * this class assumes its always through the search api
+   */
+  public function get_path() {
+    return 'search/' . arg(1) . '/' . $this->get_query_basic();
+  }
 
   /**
    * Build additional breadcrumb elements relative to $base.
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.123
diff -u -p -r1.1.2.12.2.123 apachesolr.module
--- apachesolr.module	3 Apr 2009 14:37:32 -0000	1.1.2.12.2.123
+++ apachesolr.module	3 Apr 2009 18:01:31 -0000
@@ -695,7 +695,7 @@ function apachesolr_block($op = 'list', 
             }
 
             $sort_links = array();
-            $path = 'search/' . arg(1) . '/' . $query->get_query_basic();
+            $path = $query->get_path();
             $new_query = clone $query;
             foreach ($sorts as $type => $sort) {
               $new_sort = isset($solrsorts[$type]) ? $solrsorts[$type] == 'asc' ? 'desc' : 'asc' : $sort['default'];
@@ -747,17 +747,17 @@ function apachesolr_facet_block($respons
         $facet_text = $facet;
       }
       $new_query = clone $query;
-      if ($active = $query->has_field($facet_field, $facet)) {
+      if ($active = $query->has_facet($facet_field, $facet)) {
         $contains_active = TRUE;
-        $new_query->remove_field($facet_field, $facet);
+        $new_query->remove_facet($facet_field, $facet);
         // TODO: don't assume 'search' - find the real path.
-        $path = 'search/'. arg(1) .'/'. $new_query->get_query_basic();
+        $path = $new_query->get_path();
         $querystring = $new_query->get_url_querystring();
         $unclick_link = theme('apachesolr_unclick_link', $path, $querystring);
       }
       else {
-        $new_query->add_field($facet_field, $facet);
-        $path = 'search/'. arg(1) .'/'. $new_query->get_query_basic();
+        $new_query->add_facet($facet_field, $facet);
+        $path = $new_query->get_path();
         $querystring = $new_query->get_url_querystring();
       }
       $countsort = $count == 0 ? '' : 1 / $count;
@@ -1057,7 +1057,7 @@ function apachesolr_facetcount_save($edi
  *
  * function my_module_apachesolr_modify_query(&$query, &$params) {
  *   // I only want to see articles by the admin!
- *   $query->add_field("uid", 1);
+ *   $query->add_facet("uid", 1);
  *
  * }
  */
@@ -1100,7 +1100,7 @@ function apachesolr_has_searched($search
  */
 function apachesolr_get_solr($host = NULL, $port = NULL, $path = NULL) {
   static $solr_cache;
-
+  
   if (empty($host)) {
     $host = variable_get('apachesolr_host', 'localhost');
   }
@@ -1144,6 +1144,15 @@ function apachesolr_static_response_cach
  * The query object is built from the keys, filters, and sort.
  */
 function apachesolr_drupal_query($keys = '', $filters = '', $solrsort = '') {
+  if (empty($keys)) {
+    $keys = search_get_keys();
+  }
+  if (empty($filters) && !empty($_GET['filters'])) {
+    $filters = $_GET['filters'];
+  }
+  if (empty($solrsort) && !empty($_GET['solrsort'])) {
+    $solrsort = $_GET['solrsort'];
+  }
 
   list($module, $class) = variable_get('apachesolr_query_class', array('apachesolr', 'Solr_Base_Query'));
   include_once drupal_get_path('module', $module) .'/'. $class .'.php';
@@ -1155,37 +1164,21 @@ function apachesolr_drupal_query($keys =
     watchdog('Apache Solr', $e->getMessage(), NULL, WATCHDOG_ERROR);
     $query = NULL;
   }
+  
+  apachesolr_current_query($query);
   return $query;
 }
 
 /**
- * Factory function for query objects representing the current search URL.
- *
- * The query object is built from the keys in the URL, but these may be
- * overridden by passing in parameters.
+ * Static getter/setter for the current query
  */
-function apachesolr_current_query($keys = '', $filters = '', $solrsort = '', $reset = FALSE) {
-  static $_queries = array();
-
-  if ($reset) {
-    $_queries = array();
-  }
-
-  if (empty($keys)) {
-    $keys = search_get_keys();
-  }
-  if (empty($filters) && !empty($_GET['filters'])) {
-    $filters = $_GET['filters'];
-  }
-  if (empty($solrsort) && !empty($_GET['solrsort'])) {
-    $solrsort = $_GET['solrsort'];
-  }
-  $index = $keys . '&filters=' . $filters;
-
-  if (empty($_queries) || !array_key_exists($index, $_queries)) {
-    $_queries[$index] = apachesolr_drupal_query($keys, $filters, $solrsort);
+function apachesolr_current_query($query = NULL) {
+  static $query_obj = NULL;
+  if (!empty($query)) {
+    $query_obj = $query;
   }
-  return is_object($_queries[$index]) ? clone $_queries[$index] : $_queries[$index];
+  
+  return $query_obj;
 }
 
 /**
@@ -1343,3 +1336,59 @@ function theme_apachesolr_sort_list($ite
   return theme('item_list', $items);
 }
 
+/**
+ * The interface for which all 'query' objects talk
+ */
+interface Drupal_Solr_Query_Interface {
+  /**
+   * Checks to see if the facet has been applied
+   *
+   * @param string $field
+   * the facet field to check
+   *
+   * @param string $value
+   * The facet value to check against
+   */
+  function has_facet($field, $value);
+  
+  /**
+   * Remove a facet from the query
+   *
+   * @param string $field
+   * the facet field to remove
+   *
+   * @param string $value
+   * The facet value to remove
+   * This value can be NULL
+   */
+  function remove_facet($field, $value = NULL);
+  
+  /**
+   * add a facet to a query
+   *
+   * @param string $field
+   * the facet field to apply to this query
+   *
+   * @param string value
+   * the value of the facet to apply
+   */
+  function add_facet($field, $value);
+  
+  /**
+   * return the search path
+   */
+  function get_path();
+  
+  /**
+   * return any query string for use in the l function
+   *
+   * @see l()
+   */
+  function get_url_querystring();
+  
+  /**
+   * return the basic string query
+   */
+  function get_query_basic();
+}
+
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.80
diff -u -p -r1.1.2.6.2.80 apachesolr_search.module
--- apachesolr_search.module	3 Apr 2009 14:37:32 -0000	1.1.2.6.2.80
+++ apachesolr_search.module	3 Apr 2009 18:01:31 -0000
@@ -90,7 +90,7 @@ function apachesolr_search_search($op = 
 
       try {
         // This is the object that knows about the query coming from the user.
-        $query = apachesolr_current_query($keys);
+        $query = apachesolr_drupal_query($keys);
         if (is_null($query)) {
           throw new Exception(t('Could not construct a Solr query in function apachesolr_search_search()'));
         }
@@ -469,16 +469,16 @@ function apachesolr_search_block($op = '
               unset($active);
               $term = taxonomy_get_term($tid);
               $new_query = clone $query;
-              if ($active = $query->has_field('tid', $tid)) {
+              if ($active = $query->has_facet('tid', $tid)) {
                 $contains_active = TRUE;
-                $new_query->remove_field('tid', $term->tid);
-                $path = 'search/' . arg(1) . '/' . $new_query->get_query_basic();
+                $new_query->remove_facet('tid', $term->tid);
+                $path = $new_query->get_path();
                 $querystring = $new_query->get_url_querystring();
                 $unclick_link = theme('apachesolr_unclick_link', $path, $querystring);
               }
               else {
-                $new_query->add_field('tid', $term->tid);
-                $path = 'search/' . arg(1) . '/' . $new_query->get_query_basic();
+                $new_query->add_facet('tid', $term->tid);
+                $path = $new_query->get_path();
                 $querystring = $new_query->get_url_querystring();
               }
               $countsort = $count == 0 ? '' : 1 / $count;
@@ -507,8 +507,7 @@ function apachesolr_search_block($op = '
         switch ($delta) {
           case 'currentsearch':
             $fields = $query->get_fields();
-            $search_keys = $query->get_query_basic();
-            $path = 'search/' . arg(1) . '/' . $search_keys;
+            $path = $query->get_path();
             $options = array();
             if (!$fields) {
               $options['attributes']['class'] = 'active';
@@ -517,8 +516,8 @@ function apachesolr_search_block($op = '
             foreach($fields as $field) {
               if ($field['#name']) {
                 $new_query = clone $query;
-                $new_query->remove_field($field['#name'], $field['#value']);
-                $path = 'search/'. arg(1) .'/'. $new_query->get_query_basic();
+                $new_query->remove_facet($field['#name'], $field['#value']);
+                $path = $new_query->get_path();
                 $querystring = $new_query->get_url_querystring();
                 $unclick_link = theme('apachesolr_unclick_link', $path, $querystring);
                 if (! $fielddisplay = theme("apachesolr_breadcrumb_". $field['#name'], $field['#value'])) {
Index: contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/contrib/apachesolr_nodeaccess/Attic/apachesolr_nodeaccess.module,v
retrieving revision 1.1.2.6
diff -u -p -r1.1.2.6 apachesolr_nodeaccess.module
--- contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module	20 Feb 2009 19:31:16 -0000	1.1.2.6
+++ contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module	3 Apr 2009 18:01:31 -0000
@@ -29,10 +29,10 @@ function _apachesolr_nodeaccess_build_su
       // Catch the exception to null out the query.
       throw new Exception("This user cannot access any content!");
     }
-    $node_access_query = apachesolr_drupal_query();
+    $node_access_query = apachesolr_current_query();
     foreach ($grants as $realm => $gids) {
       foreach ($gids as $gid) {
-        $node_access_query->add_field('nodeaccess_' . $realm, $gid);
+        $node_access_query->add_facet('nodeaccess_' . $realm, $gid);
       }
     }
     return $node_access_query;
Index: contrib/apachesolr_nodeaccess/tests/apachesolr_nodeaccess.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/contrib/apachesolr_nodeaccess/tests/Attic/apachesolr_nodeaccess.test,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 apachesolr_nodeaccess.test
--- contrib/apachesolr_nodeaccess/tests/apachesolr_nodeaccess.test	22 Nov 2008 10:28:17 -0000	1.1.2.1
+++ contrib/apachesolr_nodeaccess/tests/apachesolr_nodeaccess.test	3 Apr 2009 18:01:31 -0000
@@ -84,7 +84,7 @@ class DrupalApacheSolrNodeAccess extends
     $this->drupalLogin($basic_user);
 
     include_once drupal_get_path('module', 'apachesolr') .'/Solr_Base_Query.php';
-    $query = apachesolr_drupal_query();
+    $query = apachesolr_current_query();
     $params = array();
 
     $subquery = _apachesolr_nodeaccess_build_subquery($basic_user);
Index: tests/solr_base_query.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/tests/solr_base_query.test,v
retrieving revision 1.1.4.9
diff -u -p -r1.1.4.9 solr_base_query.test
--- tests/solr_base_query.test	21 Nov 2008 21:23:36 -0000	1.1.4.9
+++ tests/solr_base_query.test	3 Apr 2009 18:01:31 -0000
@@ -41,7 +41,7 @@ class DrupalSolrQueryTests extends Drupa
     foreach ($this->queries as $string) {
       $query = apachesolr_drupal_query($string, TRUE);
       // force the query to be rebuilt without removing any fields.
-      $query->remove_field('fake-field-name');
+      $query->remove_facet('fake-field-name');
       $this->assertEqual($string, $query->get_query());
     }
   }
@@ -49,7 +49,7 @@ class DrupalSolrQueryTests extends Drupa
   function testAddTerm() {
     foreach ($this->queries as $string) {
       $query = apachesolr_drupal_query($string, TRUE);
-      $query->add_field('wham', '1');
+      $query->add_facet('wham', '1');
       $this->assertEqual($string . ' wham:1', $query->get_query());
     }
   }
@@ -57,27 +57,27 @@ class DrupalSolrQueryTests extends Drupa
   function testRemoveTerm() {
     $string = 'foo';
     $query = apachesolr_drupal_query($string, TRUE);
-    $query->remove_field('', 'foo');
+    $query->remove_facet('', 'foo');
     $this->assertEqual('foo', $query->get_query());
 
     $string = 'foo bar';
     $query = apachesolr_drupal_query($string, TRUE);
-    $query->remove_field('', 'foo');
+    $query->remove_facet('', 'foo');
     $this->assertEqual('foo bar', $query->get_query());
 
     $string = 'foo uid:1 bar';
     $query = apachesolr_drupal_query($string, TRUE);
-    $query->remove_field('uid', '1');
+    $query->remove_facet('uid', '1');
     $this->assertEqual('foo bar', $query->get_query());
 
     $string = 'foo uid:1 bar';
     $query = apachesolr_drupal_query($string, TRUE);
-    $query->remove_field('uid');
+    $query->remove_facet('uid');
     $this->assertEqual('foo bar', $query->get_query());
 
     $string = 'foo uid:1 bar uid:2 tid:3';
     $query = apachesolr_drupal_query($string, TRUE);
-    $query->remove_field('uid', '1');
+    $query->remove_facet('uid', '1');
 
     // Not very beautiful, but probably best way there is:
     $pass = TRUE;
@@ -103,7 +103,7 @@ class DrupalSolrQueryTests extends Drupa
 
     $string = 'foo uid:1 bar uid:2 tid:3';
     $query = apachesolr_drupal_query($string, TRUE);
-    $query->remove_field('uid');
+    $query->remove_facet('uid');
     $this->assertEqual('foo bar tid:3', $query->get_query());
   }
 }
