Index: DrupalGoogleMini.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/DrupalGoogleMini.php,v
retrieving revision 1.1
diff -u -p -r1.1 DrupalGoogleMini.php
--- DrupalGoogleMini.php	8 Apr 2008 17:50:32 -0000	1.1
+++ DrupalGoogleMini.php	25 Feb 2009 18:29:13 -0000
@@ -1,46 +1,62 @@
 <?php
+// $Id$
+
+define('GOOGLE_MINI_MAX_RESULTS', variable_get('google_appliance_max_results', 1000));
+
 include_once 'GoogleMini.php';
 
 class DrupalGoogleMini extends GoogleMini {
 
-  var $cache = false;
+  var $cache = FALSE;
 
-  function __construct($debug = false, $debug_callback = null) {
-    parent::__construct($debug,$debug_callback);
+  function __construct($debug = FALSE, $debug_callback = NULL) {
+    parent::__construct($debug, $debug_callback);
+  }
+  
+  function log($message = NULL) {
+    if ($this->debug_callback) {
+      $callback = $this->debug_callback;
+      call_user_func($callback, $message);
+    }
+    watchdog("google_appliance", $message);
   }
   
   function query($iteratorClass = 'GoogleMiniResultIterator') {
     if (!db_table_exists('cache_google')) {
-      $this->cache = false;
+      $this->cache = FALSE;
     }
     if (!$this->cache) {
       return parent::query($iteratorClass);
-    } else {
-      $cached_result_obj = null;
+    }
+    else {
+      $cached_result_obj = NULL;
       $cache_key = md5($this->buildQuery());
-      $_cached_result_xml = cache_get($cache_key,'cache_google');
+      $_cached_result_xml = cache_get($cache_key, 'cache_google');
       $cached_result_xml = $_cached_result_xml->data;
       if ($cached_result_xml) {
-        $google_results = GoogleMini::resultFactory($cached_result_xml,$iteratorClass);
-        $google_debug = variable_get('google_debug',0);
+        $google_results = GoogleMini::resultFactory($cached_result_xml, $iteratorClass);
+        $google_debug = variable_get('google_debug', 0);
         if ($google_debug >= 2 ){
           if (function_exists('dpr')) {
             dpr("got cache for $cache_key");
           }
-        } elseif ($google_debug == 1)  {
-          watchdog('amnestysearch',"got cache for $cache_key at" . $_GET['q']);
         }
-      } else {
+        elseif ($google_debug == 1)  {
+          watchdog('google_appliance', "got cache for !cache_key at !url", array('!cache_key' => $cache_key, '!url' => $_GET['q']));
+        }
+      }
+      else {
         $google_results = parent::query($iteratorClass);
         //10 Min cache by default
-        cache_set($cache_key,'cache_google',$google_results->payload->asXML(),time() + variable_get('google_appliance_cache_timeout',600));
-        $google_debug = variable_get('google_debug',0);
+        cache_set($cache_key, $google_results->payload->asXML(), 'cache_google', time() + variable_get('google_appliance_cache_timeout', 600));
+        $google_debug = variable_get('google_debug', 0);
         if ($google_debug >= 2 ){
           if (function_exists('dpr')) {
             dpr("setting cache for $cache_key");
           }
-        } elseif ($google_debug == 1)  {
-          watchdog('amnestysearch',"setting cache for $cache_key at" . $_GET['q']);
+        }
+        elseif ($google_debug == 1)  {
+          watchdog('google_appliance', "setting cache for !cache_key at !url", array('!cache_key' => $cache_key, '!url' => $_GET['q']));
         }
       }
       return $google_results;
Index: GoogleFeeder.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/GoogleFeeder.php,v
retrieving revision 1.1
diff -u -p -r1.1 GoogleFeeder.php
--- GoogleFeeder.php	8 Apr 2008 17:50:32 -0000	1.1
+++ GoogleFeeder.php	25 Feb 2009 18:29:13 -0000
@@ -8,7 +8,7 @@ class GoogleFeeder {
     
   }
   
-  public function addLanguages($languages = null) {
+  public function addLanguages($languages = NULL) {
     
   }
   
@@ -20,14 +20,14 @@ class GoogleFeeder {
     
   }
   
-  public function getMetaData($key = null) {
+  public function getMetaData($key = NULL) {
     if (!$key) {
       return $this->_metaData;
     } else {
       if (isset($this->_metaData[$key])) {
         return $this->_metaData[$key];
       } else {
-        throw new Exception("Meta Data Code not found",E_WARNING);
+        throw new Exception("Meta Data Code not found", E_WARNING);
       }
     }
   }
Index: GoogleMini.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/GoogleMini.php,v
retrieving revision 1.2
diff -u -p -r1.2 GoogleMini.php
--- GoogleMini.php	8 Apr 2008 19:54:36 -0000	1.2
+++ GoogleMini.php	25 Feb 2009 18:29:13 -0000
@@ -1,6 +1,9 @@
 <?php
+// $Id$
 
-define('GOOGLE_MINI_MAX_RESULTS', variable_get('google_appliance_max_results', 1000));
+if (!defined('GOOGLE_MINI_MAX_RESULTS')) {
+  define('GOOGLE_MINI_MAX_RESULTS', 1000);
+}
 
 class GoogleMini {
 
@@ -12,21 +15,21 @@ class GoogleMini {
   private $_queryParts;
 
 
-  public function __construct($debug = false, $debug_callback = null) {
+  public function __construct($debug = FALSE, $debug_callback = NULL) {
     if ($debug) {
-      $this->debug = true;
+      $this->debug = TRUE;
       if ($debug_callback && function_exists($debug_callback)) {
         $this->debug_callback = $debug_callback;
       }
     }
   }
 
-  function log($message = null) {
+  function log($message = NULL) {
     if ($this->debug_callback) {
       $callback = $this->debug_callback;
       call_user_func($callback,$message);
     }
-    watchdog('google_search',$message);
+    error_log($message);
   }
 
   /**
@@ -64,9 +67,9 @@ class GoogleMini {
    * @param type either requiredfields or partialfields
    * @param string $join either AND or OR
    */
-  public function addMetaDataFilter($key, $values, $type = 'partialfields',  $join = 'OR') {
-    if (!in_array($type,array('partialfields','requiredfields'))) {
-      throw new GoogleMiniCriteriaException("You must provide a type of either partialfields or requiredfields",'-99');
+  public function addMetaDataFilter($key, $values, $type = 'partialfields', $join = 'OR') {
+    if (!in_array($type, array('partialfields', 'requiredfields'))) {
+      throw new GoogleMiniCriteriaException("You must provide a type of either partialfields or requiredfields", '-99');
     }
     if (is_array($values)) {
       $this->_metaDataFilters[$type][$key] = new stdClass();
@@ -86,16 +89,16 @@ class GoogleMini {
    *
    * @param array $languages
    */
-  public function setLanguageFilter($languages = null) {
+  public function setLanguageFilter($languages = NULL) {
     if ($languages) {
       if (is_array($languages)) {
-        $this->setQueryPart("lr",implode('|',$languages));
+        $this->setQueryPart("lr", implode('|',$languages));
       } else {
-        $this->setQueryPart("lr",$languages);
+        $this->setQueryPart("lr", $languages);
       }
-      return true;
+      return TRUE;
     }
-    return false;
+    return FALSE;
   }
 
   /**
@@ -108,7 +111,7 @@ class GoogleMini {
     if ($this->_queryParts['q']) {
       $this->_queryParts['q'] .= "%20daterange:$date_before..$date_after";
     } else {
-      $this->setQueryPart('q',"daterange:$date_before..$date_after");
+      $this->setQueryPart('q', "daterange:$date_before..$date_after");
     }
   }
 
@@ -122,7 +125,7 @@ class GoogleMini {
     if ($this->_queryParts['q']) {
       $this->_queryParts['q'] .= "%20site:$domain";
     } else {
-      $this->setQueryPart('q',"site:" . urlencode($domain));
+      $this->setQueryPart('q', "site:" . urlencode($domain));
     }
   }
 
@@ -138,17 +141,17 @@ class GoogleMini {
    *   *** WARNING *** Do not use this filter if your collection contains more than 50,000 documents.
    *   If the result set is very large, the sort operation could create significant delays in the display of results.
    */
-  public function setDateSort($dir = "D",$mode = 'S') {
+  public function setDateSort($dir = "D", $mode = 'S') {
       if ($dir != 'A' && $dir != 'D') {
-        throw new GoogleMiniCriteriaException(sprintf("The Sort direction provided is incorrect.  Got %s, needs to be A or D",htmlentities($dir)),E_WARNING);
+        throw new GoogleMiniCriteriaException(sprintf("The Sort direction provided is incorrect.  Got %s, needs to be A or D", htmlentities($dir)), E_WARNING);
       }
       if ($mode != 'S' && $mode != 'R') {
-        throw new GoogleMiniCriteriaException(sprintf("The Sort mode provided is incorrect.  Got %s, needs to be S or R",htmlentities($mode)),E_WARNING);
+        throw new GoogleMiniCriteriaException(sprintf("The Sort mode provided is incorrect.  Got %s, needs to be S or R", htmlentities($mode)), E_WARNING);
       }
 
       // build sort string
       // http://code.google.com/apis/searchappliance/documentation/46/xml_reference.html#request_sort_by_date
-      $this->setQueryPart('sort',"date:$dir:$mode:d1");
+      $this->setQueryPart('sort', "date:$dir:$mode:d1");
       return true;
   }
 
@@ -171,9 +174,9 @@ class GoogleMini {
    *
    * @param array $fields
    */
-  public function setMetaDataRequested($fields = null) {
+  public function setMetaDataRequested($fields = NULL) {
     if (is_array($fields)) {
-     $this->setQueryPart('getfields', implode('.',$fields));
+     $this->setQueryPart('getfields', implode('.', $fields));
     } else {
       $this->setQueryPart('getfields', $fields);
     }
@@ -187,10 +190,10 @@ class GoogleMini {
   public function setPageAndResultsPerPage($page = 0, $results = 10) {
     $end = $page * $results + $results;
     if ($end > GOOGLE_MINI_MAX_RESULTS) {
-      throw new GoogleMiniCriteriaException("You cannot get more than ".GOOGLE_MINI_MAX_RESULTS." results per page, requested $end",2);
+      throw new GoogleMiniCriteriaException("You cannot get more than ".GOOGLE_MINI_MAX_RESULTS." results per page, requested $end", 2);
     }
     $this->setQueryPart('start', $page * $results);
-    $this->setQueryPart('num',$results);
+    $this->setQueryPart('num', $results);
     return true;
   }
 
@@ -201,7 +204,7 @@ class GoogleMini {
    * @param string $enc
    */
   public function setOutputEncoding($enc) {
-    $this->setQueryPart('oe',$enc);
+    $this->setQueryPart('oe', $enc);
   }
 
  /**
@@ -210,7 +213,7 @@ class GoogleMini {
    * @param string $enc
    */
   public function setInputEncoding($enc) {
-    $this->setQueryPart('ie',$enc);
+    $this->setQueryPart('ie', $enc);
   }
 
   /**
@@ -231,27 +234,41 @@ class GoogleMini {
             foreach ($mdf->values as $value) {
              $metafilter .= '-' . $field . ':' . $value .'.';
             }
-          } elseif ($mdf->type == 'OR' || $mdf->type == 'OROR') {
+          }
+          elseif ($mdf->type == 'OR' || $mdf->type == 'OROR') {
             $vals = array();
             foreach ($mdf->values as $v) {
               $vals[] = $field . ':' . $v;
             }
             // The 'OROR' case is used on the Related Information pages, where you want
             // to search documents with one of multiple terms in multiple vocabularies.
-            // You have to join the different types with a | otherwise the date sorting gets messed up.            
+            // You have to join the different types with a | otherwise the date sorting gets messed up.
+            
+            
+            /***
+             * IMPORTANT!  The new Version of the Mini uses parenthesis.
+             * This will not work for older versions pre August 2008 (I believe).
+             *
+             * If you are using one of these versions see the patch at:
+             * which will use the old
+             *
+             */
+            
             if ($mdf->type == 'OROR') {
-              $metafilter .= join("|", $vals) . "|";
-            } else {
-              $metafilter .= join("|", $vals) . ".";
+              $metafilter .= '(' . join("|", $vals) . ")|";
+            }
+            else {
+              $metafilter .= '(' . join("|", $vals) . ").";
             }
-          } else {
+          }
+          else {
             foreach ($mdf->values as $value) {
-             $metafilter .= $field . ':' . $value .'.';
+              $metafilter .= $field . ':' . $value .'.';
             }
           }
         }
-        $metafilter = substr($metafilter,0,-1);
-        $this->setQueryPart($type,$metafilter);
+        $metafilter = substr($metafilter, 0,-1);
+        $this->setQueryPart($type, $metafilter);
       }
     }
 
@@ -262,7 +279,7 @@ class GoogleMini {
 
     if ($this->debug) {
       $this->log('Building Query');
-      $this->log(var_export($this->_queryParts,1));
+      $this->log(var_export($this->_queryParts, 1));
     }
 
     foreach ($this->_queryParts as $label => $value) {
@@ -286,15 +303,15 @@ class GoogleMini {
     // get search results in XML using cURL
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $query);
-    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-    curl_setopt($ch, CURLOPT_VERBOSE, true);
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
+    curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
 
     $resultXML = curl_exec($ch);
 	if ($this->debug) {
     	$this->log('Made CURL request to ' . $query);
 	}
 
-    return self::resultFactory($resultXML,$iteratorClass);
+    return self::resultFactory($resultXML, $iteratorClass);
   }
 
   function resultFactory($resultXML,$className = 'GoogleMiniResultIterator') {
@@ -309,7 +326,8 @@ class GoogleMini {
       if (!$payload->GM) {
         throw new GoogleMiniResultException("No Results found", '1');
       }
-    } else {
+    }
+    else {
       foreach ($payload->xpath('//R') as $res) {
         $results[] = $res;
       }
@@ -400,30 +418,30 @@ class GoogleMiniResultException extends 
 class GoogleMiniException extends Exception {
   
   function __construct($message, $code = null) {
-     parent::__construct($message,$code);
-     $this->userMessage = GoogleMiniException::getUserMessage($code);
-     if (!$this->userMessage) {
-       $this->userMessage = $message;
-     }
+      parent::__construct($message, $code);
+      $this->userMessage = GoogleMiniException::getUserMessage($code);
+      if (!$this->userMessage) {
+        $this->userMessage = $message;
+      }
   }
   
   function getErrorCodes() {
     static $error_codes;
     if (!$error_codes) {
-     $error_codes = array (
-      '-100' => 'We apologize, but the connection to our search engine appears to be down at the moment, please try again later.',
-      '-99' => 'We apologize, but your search cannot be completed at this time, please try again later.',
-      '1' => 'No results were found that matched your criteria.  Please try broadening your search.',
-      '2' => 'Sorry, but our search does not return more than 1,000 records, please refine your criteria.',
-     );
-   }
-   return $error_codes;
+      $error_codes = array (
+        '-100' => 'We apologize, but the connection to our search engine appears to be down at the moment, please try again later.',
+        '-99' => 'We apologize, but your search cannot be completed at this time, please try again later.',
+        '1' => 'No results were found that matched your criteria.  Please try broadening your search.',
+        '2' => 'Sorry, but our search does not return more than 1,000 records, please refine your criteria.',
+      );
+    }
+    return $error_codes;
   }
   
   
   function getUserMessage($code) {
-   $error_codes = $this->getErrorCodes();  
-   return $error_codes[$code];
+    $error_codes = $this->getErrorCodes();  
+    return $error_codes[$code];
   }
 }
 
Index: google_appliance.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/google_appliance.info,v
retrieving revision 1.1
diff -u -p -r1.1 google_appliance.info
--- google_appliance.info	8 Apr 2008 17:50:32 -0000	1.1
+++ google_appliance.info	25 Feb 2009 18:29:13 -0000
@@ -1,4 +1,5 @@
-; $Id: 
+; $Id$
 name = "Google Search Appliance Integration"
 description = "Provides a search interace to the googleMini or GSA, meta-data generators which will allow for advanced search and a class for talking to a GoogleMini or GSA."
 package = "Other"
+core = 6.x
\ No newline at end of file
Index: google_appliance.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/google_appliance.install,v
retrieving revision 1.1
diff -u -p -r1.1 google_appliance.install
--- google_appliance.install	8 Apr 2008 17:50:32 -0000	1.1
+++ google_appliance.install	25 Feb 2009 18:29:13 -0000
@@ -1,35 +1,80 @@
 <?php
+// $Id$
+
+/**
+ * @file
+ * Installation file for building tables for Google Integration
+ */
+
+/**
+ * Implementation of hook_install().
+ */
 function google_appliance_install() {
-  $q = "
-CREATE TABLE IF NOT EXISTS `{cache_google}` (
-  `cid` varchar(255) NOT NULL default '',
-  `data` longblob,
-  `expire` int(11) NOT NULL default '0',
-  `created` int(11) NOT NULL default '0',
-  `headers` text,
-  PRIMARY KEY  (`cid`),
-  KEY `expire` (`expire`)
-) ENGINE=innoDB DEFAULT CHARSET=utf8
-";
+  $install = drupal_install_schema('google_appliance');
   
-  $ret[] = db_query($q);
-  return $ret;
+  if ($install['0']['success'] == 1) {
+    drupal_set_message(t('Google Appliance module installed successfully'));
+  } 
+  else {
+    drupal_set_message(t('Google Appliance module failed to install'), 'error');
+  }
 }
 
-function google_appliance_update_1() {
-  $q = "
-CREATE TABLE IF NOT EXISTS `{cache_google}` (
-  `cid` varchar(255) NOT NULL default '',
-  `data` longblob,
-  `expire` int(11) NOT NULL default '0',
-  `created` int(11) NOT NULL default '0',
-  `headers` text,
-  PRIMARY KEY  (`cid`),
-  KEY `expire` (`expire`)
-) ENGINE=innoDB DEFAULT CHARSET=utf8
-";
-  
-  $ret[] = update_sql($q);  
-  return $ret;
+/**
+ * Implementation of hook_uninstall().
+ */
+function google_appliance_uninstall() {
+  // Remove tables.
+  $uninstall = drupal_uninstall_schema('google_appliance');
+
+  if ($uninstall['0']['success'] == 1) {
+    drupal_set_message(t('Google Appliance module uninstalled successfully'));
+  } 
+  else {
+    drupal_set_message(t('Google Appliance module failed to uninstall'), 'error');
+  }
 }
-?>
\ No newline at end of file
+
+/**
+ * Implementation of hook_schema().
+ */
+function google_appliance_schema() {
+  $schema['cache_google'] = array(
+    'fields' => array(
+      'cid' => array(
+        'type' => 'varchar', 
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => ''
+      ),
+      'data' => array(
+        'type' => 'blob',
+        'not null' => FALSE,
+        'size' => 'big'
+      ),
+      'expire' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0
+      ),
+      'created' => array(
+        'type' => 'int',
+        'not null' => TRUE, 
+        'default' => 0
+      ),
+      'headers' => array(
+        'type' => 'text'
+      ),
+      'serialized' => array(
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => TRUE,
+        'default' => 0
+      )
+    ),
+    'indexes' => array('expire' => array('expire')),
+    'primary key' => array('cid'),
+  );
+  
+  return $schema;
+}
\ No newline at end of file
Index: google_appliance.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/google_appliance.module,v
retrieving revision 1.1
diff -u -p -r1.1 google_appliance.module
--- google_appliance.module	8 Apr 2008 17:50:32 -0000	1.1
+++ google_appliance.module	25 Feb 2009 18:29:13 -0000
@@ -1,45 +1,28 @@
 <?php
+// $Id$
+
 /**
  * @file GSA integration
  */
 
 /**
- * Implementation of hook_menu()
- *
+ * Implementation of hook_menu().
  */
-function google_appliance_menu($may_cache = false) {
+function google_appliance_menu() {
   $items = array();
-  if ($may_cache) {
-    $items[] = array (
-    'path' => 'google_appliance',
-    'callback' => 'google_appliance_search',
-    'type' => MENU_CALLBACK,
-    'access' => true,
-    );
 
-    $items[] = array (
-      'path' => 'google_appliance_feeder',
-      'callback' => 'google_apppliance_feeder',
-      'type' => MENU_CALLBACK,
-      'access' => true,
-    );
-
-    $items[] = array(
-      'path' => 'admin/settings/google_appliance',
-      'title' => t('Google Appliance Settings'),
-      'description' => t('Configuration for the Google Appliance search'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('google_appliance_admin_settings'),
-      'access' => user_access('administer search'),
-      'type' => MENU_NORMAL_ITEM,
-    );
-  } else {
-    _google_appliance_add_meta_tags();
-  }
+  $items['admin/settings/google-appliance'] = array(
+    'title' => 'Google Appliance Settings',
+    'description' => 'Configuration for the Google Appliance search',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('google_appliance_admin_settings'),
+    'access arguments' => array('administer search'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  
   return $items;
 }
 
-
 /**
  * Implementation of hook_block().
  */
@@ -60,7 +43,8 @@ function google_appliance_block($op = 'l
       switch ($delta) {
         
         case 'recommended_links':         
-          if ($result =& google_appliance_static_response_cache()) {            
+          if ($result =& google_appliance_static_response_cache()) {
+
             $matches = $result->getKeyMatches();
             if (!$matches) {
               return;
@@ -68,13 +52,14 @@ function google_appliance_block($op = 'l
           
             $links = array();          
             foreach ($matches as $link => $title) {
-              $links[] = l($title,$link);
+              $links[] = l($title, $link);
             }
           
             if (count($links)) {
-              $block['content'] = theme('item_list',$links);
-            } else {
-              return false;
+              $block['content'] = theme('item_list', $links);
+            }
+            else {
+              return FALSE;
             }
           }
           break;
@@ -101,7 +86,7 @@ function google_appliance_admin_settings
     "#title" => t("Search Name"),
     "#description" => t('The name of this search, to appear as sub-navigation on the search page.'),
     "#default_value" => variable_get('google_appliance_name', 'Google Appliance'),
-    "#required" => true,
+    "#required" => TRUE,
   );
 
   $form["config_init"]["google_appliance_host_name"] = array(
@@ -110,7 +95,7 @@ function google_appliance_admin_settings
     "#title" => t("Host Name"),
     "#description" => t('Your Google Search Appliance host name or IP address (with http:// or https://), which were assigned when the appliance was set up.<br />You do <b>not</b> need to include "/search" at the end, or a trailing slash, but you should include a port number if needed.<br/> Example: http://mygooglebox.com'),
     "#default_value" => variable_get('google_appliance_host_name', ''),
-    "#required" => true,
+    "#required" => TRUE,
   );
 
   $form["config_init"]["google_appliance_collection"] = array(
@@ -119,7 +104,7 @@ function google_appliance_admin_settings
     "#title" => t("Collection"),
     "#description" => t('The name of the collection of indexed content to search.'),
     "#default_value" => variable_get('google_appliance_collection', ''),
-    "#required" => true,
+    "#required" => TRUE,
   );
 
   $form["config_init"]["google_appliance_client"] = array(
@@ -128,7 +113,7 @@ function google_appliance_admin_settings
     "#title" => t("Client"),
     "#description" => t('The name of a valid front-end, defined when you set up the appliance.'),
     "#default_value" => variable_get('google_appliance_client', ''),
-    "#required" => true,
+    "#required" => TRUE,
   );
   
   $form["config_init"]["google_appliance_cache_timeout"] = array(
@@ -148,12 +133,19 @@ function google_appliance_admin_settings
     "#default_value" => variable_get('google_debug', ''),    
   );
   
-
+  $form["config_init"]["google_appliance_limit_per_page"] = array(
+    "#type" => "textfield",
+    "#size" => 5,
+    "#title" => t("Number of results per page"),
+    "#description" => t('If you enter 0, it will return the max allowed by the appliance (100)'),
+    "#default_value" => variable_get('google_appliance_limit_per_page', 10),    
+  );
+  
   // error message config
   $form["config_messages"] = array(
     "#title" => t("Error Messages"),
     "#type" => "fieldset",
-    "#collapsible" => true,
+    "#collapsible" => TRUE,
   );
 
   $form["config_messages"]["google_appliance_errorcode_1"] = array(
@@ -161,7 +153,7 @@ function google_appliance_admin_settings
     "#type" => "textfield",
     "#size" => 100,
     "#maxlength" => 255,
-    "#required" => true,
+    "#required" => TRUE,
     "#description" => t('If there are no results for the search criteria.'),
     "#default_value" => variable_get('google_appliance_errorcode_1', 'No results were found that matched your criteria. Please try broadening your search.'),
   );
@@ -171,7 +163,7 @@ function google_appliance_admin_settings
     "#type" => "textfield",
     "#size" => 100,
     "#maxlength" => 255,
-    "#required" => true,
+    "#required" => TRUE,
     "#description" => t('If there are more than 1,000 results for the search criteria.'),
     "#default_value" => variable_get('google_appliance_errorcode_2', 'Sorry, but our search does not return more than 1,000 records, please refine your criteria.'),
   );
@@ -181,7 +173,7 @@ function google_appliance_admin_settings
     "#type" => "textfield",
     "#size" => 100,
     "#maxlength" => 255,
-    "#required" => true,
+    "#required" => TRUE,
     "#description" => t('If the search cannot perform due to a query error.'),
     "#default_value" => variable_get('google_appliance_errorcode_neg_99', 'We apologize, but your search cannot be completed at this time, please try again later.'),
   );
@@ -191,100 +183,22 @@ function google_appliance_admin_settings
     "#type" => "textfield",
     "#size" => 100,
     "#maxlength" => 255,
-    "#required" => true,
+    "#required" => TRUE,
     "#description" => t('If the search cannot connect to the Google Appliance server.'),
     "#default_value" => variable_get('google_appliance_errorcode_neg_100','We apologize, but the connection to our search engine appears to be down at the moment, please try again later.'),
   );
 
-  // optional metadata configuration
-  /*
-  $form["config_metadata"] = array(
-    "#title" => t("Metadata Configuration"),
-    "#type" => "fieldset",
-    "#collapsible" => true,
-  );
-  */
-
   // last but not least, submit
   $form["submit"] = array(
     "#type" => "submit",
     "#value" => t("Save Settings"),
   );
 
-  return $form;
-}
-
-/**
- * Validation function, though it's actually getting overridden by the #required fields...
- *
- */
-function google_appliance_admin_settings_validate($form_id, $form) {
-  if (empty($form['google_appliance_host_name'])) {
-    form_set_error('google_appliance_host_name', t('Please enter your host name or IP address.'));
-  }
-
-  if (empty($form['google_appliance_collection'])) {
-    form_set_error('google_appliance_collection', t('Please enter the name of the collection you want to search.'));
-  }
-
-  if (empty($form['google_appliance_client'])) {
-    form_set_error('google_appliance_client', t('Please enter name of the client frontend you are searching.'));
-  }
-
-  if (empty($form['google_appliance_name'])) {
-    form_set_error('google_appliance_name', t('Please enter the name of this search, to appear as sub-navigation on the search page.'));
-  }
+  return system_settings_form($form);
 }
 
 /**
- * Submits the admin settings form and saves all the variables.
- */
-function google_appliance_admin_settings_submit($form_id, $form) {
-  variable_set('google_appliance_host_name', check_plain($form['google_appliance_host_name']));
-  variable_set('google_appliance_collection', check_plain($form['google_appliance_collection']));
-  variable_set('google_appliance_client', check_plain($form['google_appliance_client']));
-  variable_set('google_appliance_name', check_plain($form['google_appliance_name']));
-  variable_set('google_appliance_cache_timeout', check_plain($form['google_appliance_cache_timeout']));
-  variable_set('google_debug', check_plain($form['google_debug']));
-
-  // don't run check_plain on these because they can have HTML
-  variable_set('google_appliance_errorcode_1', $form['google_appliance_errorcode_1']);
-  variable_set('google_appliance_errorcode_2', $form['google_appliance_errorcode_2']);
-  variable_set('google_appliance_errorcode_neg_99', $form['google_appliance_errorcode_neg_99']);
-  variable_set('google_appliance_errorcode_neg_100', $form['google_appliance_errorcode_neg_100']);
-
-  drupal_set_message(t('Your settings have been saved.'));
-}
-
-/**
- * Invokes the google_appliance_appconfig hook to add <meta> tags to nodes
- * for indexing metadata by the google crawler.
- *
- */
-function _google_appliance_add_meta_tags() {
-  if (arg(0) == 'node' && is_numeric(arg(1))) {
-    $node = node_load(arg(1));
-    theme('add_google_appliance_meta_tags', $node);
-  }
-}
-
-function google_appliance_feeder() {
-  //not sure if this is appropriate as everything should be findable via the main site, but this basically just creates a listing of all nodes.
-  $result = db_query('SELECT * from {node} WHERE status = 1');
-  print '<html>';
-  print '<body>';
-
-  while ($row = db_fetch_object($result)) {
-    print l($row->title,'node/' . $row->nid);
-  }
-
-  print '</body>';
-  print '</html>';
-  die();
-}
-
-/**
- * Implementation of hook_search()
+ * Implementation of hook_search().
  *
  * @param string $op
  *  Operation - name, reset, search, status
@@ -293,28 +207,44 @@ function google_appliance_feeder() {
  * @return
  *  Array of search results (each is an assoc. array) that can be fed to a theme function
  */
-function google_appliance_search($op = 'search', $keys = null) {
+function google_appliance_search($op = 'search', $keys = NULL) {
   switch ($op) {
     case 'name':
       return t(variable_get('google_appliance_name', "Google Appliance"));
       break;
 
     case 'search':
+      global $pager_page_array, $pager_total, $pager_total_items;
+      $page = isset($_GET['page']) ? $_GET['page'] : '';
+      // Convert comma-separated $page to an array, used by other functions.
+      $pager_page_array = explode(',', $page);
+      // $element indicates which of the pagers active this pager is working from.  $limit indicates how many per page.
+      $element = 0;
+      $limit = variable_get('google_appliance_limit_per_page', 10);
+      
       $dir = drupal_get_path('module', 'google_appliance');
       include_once $dir . '/DrupalGoogleMini.php';
       
       $google_debug = variable_get('google_debug',0);
-      if ($google_debug >= 2 ){
-          $gm = new DrupalGoogleMini(true,'dpr');
-        } elseif ($google_debug == 1)  {
-          $gm = new DrupalGoogleMini(true);
-        } else {
-          $gm = new DrupalGoogleMini(false);
+      if ($google_debug >= 2 ) {
+          $gm = new DrupalGoogleMini(TRUE, 'dpr');
         }
+        elseif ($google_debug == 1)  {
+          $gm = new DrupalGoogleMini(TRUE);
+        }
+        else {
+          $gm = new DrupalGoogleMini(FALSE);
+        }
+      
+      /**
+       * If you have many searches for the same content
+       * You can use this setting to keep the GSA from getting hit too often
+       *
+       */
       
-      if ($cache = variable_get('google_appliance_cache_timeout',0) ) {
-        cache_clear_all(null,'cache_google');
-        $gm->cache = true;
+      if ($cache = variable_get('google_appliance_cache_timeout', 0) ) {
+        cache_clear_all(NULL, 'cache_google');
+        $gm->cache = TRUE;
       }
 
       // initialize search object
@@ -324,15 +254,16 @@ function google_appliance_search($op = '
         $gm->setMetaDataRequested('*');
 
         // get configuration from settings page
-        $_tmp_host = variable_get('google_appliance_host_name', false);
+        $_tmp_host = variable_get('google_appliance_host_name', FALSE);
         if (!$_tmp_host) {
           drupal_set_message(t('No host name has been configured for the search appliance. Please enter it on the <a href="@admin-url">Google Appliance settings page</a>', array("@admin-url" => url("admin/settings/search/google_appliance"))), 'error');
-          return false;
+          return FALSE;
         }
         $gm->baseUrl = $_tmp_host . "/search";
         $gm->collection = variable_get('google_appliance_collection', '');
-        $gm->setQueryPart('client',variable_get('google_appliance_client', ''));
-
+        $gm->setQueryPart('client', variable_get('google_appliance_client', ''));
+        $gm->setPageAndResultsPerPage($page, $limit);
+        
         // set search parameters
         $gm->setKeywords($keys);
         
@@ -344,17 +275,19 @@ function google_appliance_search($op = '
       }
       catch (GoogleMiniCriteriaException $e) {
         $code = $e->getCode();
-        if ($message = variable_get('google_appliance_errorcode_' . $code,'')) {
+        if ($message = variable_get('google_appliance_errorcode_' . $code, '')) {
           $user_message = $message;
-        } else {
+        }
+        else {
           $user_message = GoogleMiniException::getUserMessage($code);  
         }
         
         $error_message = $e->getMessage();
         if ($code > 0) {
-            $output .= "<h2>" . $user_message . "</h2>";
-            return $output;
-        } else {
+          $output .= "<h2>" . $user_message . "</h2>";
+          return $output;
+        }
+        else {
           watchdog('google_appliance', $error_message);
           drupal_set_message($error_message, 'error');
         }
@@ -365,17 +298,12 @@ function google_appliance_search($op = '
       try {
         $resultIterator = $gm->query();
         google_appliance_static_response_cache($resultIterator);
+        // Google never returns more than 1000 results, so we ignore any values larger than that.
+        $pager_total_items[$element] = ($resultIterator->totalResults < 1000) ? $resultIterator->totalResults : 1000;
+        $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
+        $pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
+        
         foreach ($resultIterator as $key => $result) {
-          /*$results[] = array('link' => url('node/'. $doc->nid, NULL, NULL, TRUE),
-                               'type' => node_get_types('name', $doc),
-                               'title' => $doc->title,
-                               'user' => theme('username', $doc),
-                               'date' => $doc->changed,
-                               'node' => $doc,
-                               'extra' => $extra,
-                               'score' => $doc->score,
-                               'snippet' => $snippet);
-                                         */
           $results[] = theme('google_appliance_search_result_array', $result);
         }
       }
@@ -384,9 +312,8 @@ function google_appliance_search($op = '
           google_appliance_static_response_cache($resultIterator);
         }
         drupal_set_message($e->getMessage());
-        return false;
+        return FALSE;
       }
-
       return $results;
       break;
 
@@ -397,66 +324,17 @@ function google_appliance_search($op = '
   }
 }
 
-
-function theme_add_google_appliance_meta_tags($node) {
-  // create list of tags to add
-  $results = array();
-
-  /**
-   * Adding taxonomy tags
-   */
-  $vocabs = taxonomy_get_vocabularies();
-  if (module_exists('nat') && $node->nat) {
-    $node->taxonomy = array_merge($node->nat,$node->taxonomy);
-    //$node->taoxnomy[] = $
-  }
-  foreach ($node->taxonomy as $term ) {
-    $tagname = 'category-' . strtolower($vocabs[$term->vid]->name);
-    $results[] = array($tagname, $term->name);
-  }
-
-  /**
-   * Adding sort date IMPORTANT: for sorting, mini must be configured to use htis tag
-   */
-  
-  $results[] = array('date', date('Y-m-d h:i:s', $node->changed));
-  $results[] = array('created', date('Y-m-d h:i:s', $node->created));
-  
-  /**
-   * Normally this doesn't matter, 
-   * but if you want to allow the gsa to 
-   * access unpublished pages and later filter
-   * on this you will need it.
-   */
-  $results[] = array('status', $node->status);
-  
-
-  /**
-   * i18n configuration
-   */
-  if ($node->language) {
-    $results[] = array('content-language', $node->language);
-  }
-
-  /**
-   * node type
-   */
-  $results[] = array('type', $node->type);
-  
-  /**
-   * Author
-   */
-  $node->uid = empty($node->uid) ? 0: $node->uid;
-  $user = user_load(array('uid' => 0));
-  $user->name = empty($user->name) ? 'anonymous' : $user->name;
-  $results[] = array('author' => $user->name);
-  
-  // add meta tags
-  foreach ($results as $res) {
-    list($name, $content) = $res;
-    $content = strip_tags($content);
-    drupal_set_html_head('<meta name="'. htmlentities($name) .'" content="'. htmlentities($content) .'" />');
-  }
+/**
+ * Implementation of hook_theme().
+ */
+function google_appliance_theme() {
+  return array(
+    'google_appliance_search_result_array' => array(
+      'arguments' => array(
+        'result' => array()
+      )
+    ),
+  );
 }
 
 function theme_google_appliance_search_result_array($result) {  
@@ -470,63 +348,65 @@ function theme_google_appliance_search_r
   );
 }
 
-function google_appliance_form_alter($form_id,&$form) {
-   if ($form_id == 'block_admin_configure'){
+/**
+ * Implementation of hook_form_alter().
+ */
+function google_appliance_form_alter(&$form, $form_state, $form_id) {
+  if ($form_id == 'block_admin_configure') {
     $module = $form['module']['#value'];
     $delta = $form['delta']['#value'];
     $var_name = $module . '-' .$delta;
 
     $ga_blocksettings = google_appliance_blocksettings_get();
 
-    $form['block_settings']['google_appliance'] = array (
-    '#type' => 'fieldset',
-    '#title' => t("Google Appliance Settings"),
-    '#description' => t(''),
-    '#collapsed' => true,
-    '#collapsible' => true,
-    '#tree' => true,
-    '#weight' => -1,
+    $form['block_settings']['google_appliance'] = array(
+      '#type' => 'fieldset',
+      '#title' => t("Google Appliance Settings"),
+      '#description' => t(''),
+      '#collapsed' => TRUE,
+      '#collapsible' => TRUE,
+      '#tree' => TRUE,
+      '#weight' => -1,
     );
 
-    $form['block_settings']['google_appliance']['hide'] = array (
-    '#type' => 'radios',
-    '#title' => t("Do you want to hide this block from the GSA crawler?"),
-    '#description' => t('Select No if you want this block content to be crawled with the page content.'),
-    '#options' => array(1 => t('Yes'), 0 => t('No')),
-    '#default_value' => isset($ga_blocksettings[$var_name]) ? $ga_blocksettings[$var_name] : 1,
-    '#collapsed' => true,
-    '#collapsible' => true,
-    '#tree' => true,
+    $form['block_settings']['google_appliance']['hide'] = array(
+      '#type' => 'radios',
+      '#title' => t("Do you want to hide this block from the GSA crawler?"),
+      '#description' => t('Select No if you want this block content to be crawled with the page content.'),
+      '#options' => array(1 => t('Yes'), 0 => t('No')),
+      '#default_value' => isset($ga_blocksettings[$var_name]) ? $ga_blocksettings[$var_name] : 1,
+      '#collapsed' => TRUE,
+      '#collapsible' => TRUE,
+      '#tree' => TRUE,
     );
 
-    $form['#submit']['google_appliance_block_save'] = array();
+    $form['#submit'][] = 'google_appliance_block_save';
     return $form;
 
-   }
+  }
 }
 
-function google_appliance_block_save($form_id,$form_values) {
-  $var_name = $form_values['module'] . '-' . $form_values['delta'];
+function google_appliance_block_save(&$form, $form_state) {
+  $var_name = $form_state['values']['module'] . '-' . $form_state['values']['delta'];
   $block_settings = google_appliance_blocksettings_get();
-  if (!isset($form_values['google_appliance']['hide'])) {
+  if (!isset($form_state['values']['google_appliance']['hide'])) {
     unset($block_settings[$var_name]);
-  } else {
-    $block_settings[$var_name] = $form_values['google_appliance']['hide'];
+  }
+  else {
+    $block_settings[$var_name] = $form_state['values']['google_appliance']['hide'];
   }
 
   google_appliance_blocksettings_set($block_settings);
 }
 
-
 function google_appliance_blocksettings_set($new_val) {
-  variable_set('google_appliance_block_settings',$new_val);
+  variable_set('google_appliance_block_settings', $new_val);
 }
 
-
 function google_appliance_blocksettings_get() {
   static $google_appliance;
   if (empty($google_appliance)) {
-    $google_appliance = variable_get('google_appliance_block_settings',array());
+    $google_appliance = variable_get('google_appliance_block_settings', array());
   }
   return $google_appliance;
 }
@@ -535,11 +415,10 @@ function google_appliance_block_nogoogle
   $gsa_block_settings = google_appliance_blocksettings_get();
   $var_name = $block->module . '-' . $block->delta;
   if (!isset($gsa_block_settings[$var_name]) || $gsa_block_settings[$var_name]) {
-    return true;
+    return TRUE;
   }
 }
 
-
 /**
  * It is important to hold on to the Google Appliance response object for the duration of the
  * page request so that we can use it for things like the keymatch block
@@ -557,11 +436,8 @@ function &google_appliance_static_respon
   return $_response;
 }
 
-
 function google_appliance_simpletest() {
   $dir = drupal_get_path('module', 'google_appliance'). '/tests';
   $tests = file_scan_directory($dir, '\.test$');
   return array_keys($tests);
-}
-
-?>
\ No newline at end of file
+}
\ No newline at end of file
