Index: Solr_Base_Query.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/Solr_Base_Query.php,v
retrieving revision 1.1.2.8
diff -u -p -r1.1.2.8 Solr_Base_Query.php
--- Solr_Base_Query.php	27 Nov 2008 18:47:58 -0000	1.1.2.8
+++ Solr_Base_Query.php	19 Mar 2009 21:32:29 -0000
@@ -28,20 +28,24 @@ class Solr_Base_Query {
    *
    * Extract a module-specific search option from a search query. e.g. 'type:book'
    */
-  static function query_extract($keys, $option) {
-    $pattern = '/(^| )'. $option .':(\"([^\"]*)\")/i';
-    preg_match_all($pattern, $keys, $matches);
-    if (!empty($matches[2])) {
-      // The preg_replace removes beginning and trailing quotations.
-      return preg_replace('/^"|"$/', '', $matches[2]);
-    }
-    $pattern = '/(^| )'. $option .':([^ ]*)/i';
-    if (preg_match_all($pattern, $keys, $matches)) {
-      if (!empty($matches[2])) {
-        return $matches[2];
+  static function query_extract($filters, $name) {
+    $values = array();
+    // Range queries.  The "TO" is case-sensitive.
+    $patterns[] = '/(^| )'. $name .':(\[\S+ TO \S+\])/';
+    // Match quoted values.
+    $patterns[] = '/(^| )'. $name .':"([^"]*)"/';
+    // Match unquoted values.
+    $patterns[] = '/(^| )'. $name .':([^ ]*)/';
+    foreach ($patterns as $p) {
+      if (preg_match_all($p, $filters, $matches)) {
+        $values = array_merge($matches[2], $values);
       }
+      // Update the local copy of $filters by removing all matches.
+      $filters = trim(str_replace($matches[0], '', $filters));
     }
+    return $values;
   }
+    
 
   /**
    * Replaces all occurances of $option in $keys.
@@ -67,10 +71,12 @@ class Solr_Base_Query {
       return implode(' ', array_filter(explode(' ', $values['#value']), 'trim'));
     }
     else {
-      // if the field value has spaces in it, wrap it in double quotes.
-      if (count(explode(' ', $values['#value'])) > 1) {
-        $values['#value'] = '"'. $values['#value']. '"';
+      // If the field value has spaces, or : in it, wrap it in double quotes.
+      // unless it is a range query.
+      if (preg_match('/[ :]/', $field['#value']) && !preg_match('/\[\S+ TO \S+\]/', $field['#value'])) {
+        $field['#value'] = '"'. $field['#value']. '"';
       }
+      
       return $values['#name']. ':'. $values['#value'];
     }
   }
