Index: handlers/location_handler_filter_location_province.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/location/handlers/location_handler_filter_location_province.inc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 location_handler_filter_location_province.inc
--- handlers/location_handler_filter_location_province.inc	14 Jan 2009 16:46:24 -0000	1.1.2.1
+++ handlers/location_handler_filter_location_province.inc	7 Nov 2009 22:09:22 -0000
@@ -26,7 +26,7 @@
    */
   function value_form(&$form, &$form_state) {
     $country = $this->grovel_country();
-
+    $country = $this->filter_province_country($country);
     drupal_add_js(drupal_get_path('module', 'location') .'/location_autocomplete.js');
 
     $ac = $country;
@@ -52,20 +52,29 @@
   }
 
   function operator_options() {
-    if ($this->options['multiple']) {
-      return array(
-        'is' => t('Is one of'),
-        'is not' => t('Is not one of'),
-      );
-    }
-    else {
-      return array(
-        'is' => t('Is'),
-        'is not' => t('Is not'),
+    return array(
+      'is' => t('Is'),
+      'is not' => t('Is not'),
+      'word' => t('Contains any word'),
+      'not word' => t('Does not contain'),
       );
-    }
   }
 
+  // This function will set the province fields for the Views Admin UI filter autocomplete
+  function filter_province_country(&$country) {
+    // We're editing the view, make sure this View hasn't been initiated 
+    if (!$this->view->inited) {
+      $current_view = $this->view->current_display;
+      $view_filters = $this->view->display[$current_view]->display_options['filters'];
+      foreach ($view_filters as $field=>$v) {
+        if ($field == 'country') {
+          $country = $v['value'];
+        }
+      }
+    }
+    return $country;
+  } 
+
   function grovel_country() {
     $country = variable_get('location_default_country', 'us');
     if (!empty($this->view->filter))
@@ -90,42 +99,57 @@
 
   function query() {
     // Normalize values.
-    $value = $this->value;
-    if (is_array($value)) {
-      // At one point during development, provinces was a select box.
-      // Right now it's an autocomplete textfield.
-      // @@@ Investigate correct fix sometime.
-      //$value = array_keys($value);
-      if (count($value) == 1) {
-        // If multiple is allowed but only one was chosen, use a string instead.
-        $value = reset($value);
-      }
+    // If province is exposed, Views will return a single value array 
+    if (is_array($this->value)) {
+      $value = (strpos($this->value[0], ',') > 0) ? explode(',', $this->value[0]) : $this->value[0];
+    }
+    // If province is not exposed, View will return a string
+    else {
+      $value = (strpos($this->value, ',') > 0) ? explode(',', $this->value) : $this->value;
     }
     if (empty($value)) {
       return;
     }
-
+    
     $country = $this->grovel_country();
 
     $this->ensure_my_table();
     $field = "$this->table_alias.$this->real_field";
-
-
     if (is_array($value)) {
       // Multiple values
       foreach ($value as $k => $v) {
         // Convert to province codes.
+        $v = trim($v);
         $value[$k] = location_province_code($country, $v);
       }
-      $placeholders = db_placeholders($value, 'varchar');
-      $operator = ($this->operator == 'is') ? 'IN' : 'NOT IN';
-      $this->query->add_where($this->options['group'], "$field $operator($placeholders)", $value);
+      
+      // Multiple provinces: "is" use "word", "is not" use "not word" 
+      switch ($this->operator) {
+        case 'is not':
+        case 'not word':
+          $notword = "NOT ";
+        case 'is': 
+        case 'word':
+          foreach ($value as $word) {
+            $where[] = "$upper(%s) LIKE $upper('%%%s%%')";
+            $values[] = $field;
+            $values[] = trim($word, " ,!?");
+          }
+    
+          if (!$where) {
+            return;
+          }
+      
+          $where = $notword . '(' . implode(' OR ', $where) . ')';
+          $this->query->add_where($this->options['group'], $where, $values);
+          break;
+      }        
     }
     else {
       // Single value
       // Convert to province code.
       $value = location_province_code($country, $value);
-      $operator = ($this->operator == 'is') ? '=' : '!=';
+      $operator = (($this->operator == 'is') || ($this->operator == 'word')) ? '=' : '!=';
       $this->query->add_where($this->options['group'], "$field $operator '%s'", $value);
     }
   }
Index: location.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/location/location.module,v
retrieving revision 1.222.2.20
diff -u -r1.222.2.20 location.module
--- location.module	3 Mar 2009 20:07:19 -0000	1.222.2.20
+++ location.module	16 Dec 1980 00:07:47 -0000
@@ -913,8 +913,16 @@
  */
 function _location_autocomplete($country, $string = '') {
   $counter = 0;
-  $string   = strtolower($string);
-  $string   = '/^'. $string .'/';
+  
+  $string   = explode(',', $string);
+  
+  // Get the last value 
+  $last = trim(array_pop($string));
+  $last = strtolower($last);
+  $last   = '/^'. $last .'/';
+  
+  // Prepare the remaining values for display 
+  $prefix = (count($string) && ($last != '')) ? implode(',', $string) . ',' : ''; 
   $matches  = array();
 
   if (strpos($country, ',') !== FALSE) {
@@ -932,8 +940,8 @@
   if (!empty($provinces)) {
     while (list($code, $name) = each($provinces)) {
       if ($counter < 5) {
-        if (preg_match($string, strtolower($name))) {
-          $matches[$name] = $name;
+        if (preg_match($last, strtolower($name))) {
+          $matches[$prefix . $name] = $name;
           ++$counter;
         }
       }

