You are here

class DrupalGoogleMini in Google Search Appliance 6.2

Same name and namespace in other branches
  1. 5 DrupalGoogleMini.php \DrupalGoogleMini

Hierarchy

Expanded class hierarchy of DrupalGoogleMini

File

./DrupalGoogleMini.php, line 7

View source
class DrupalGoogleMini extends GoogleMini {
  var $cache = FALSE;
  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 getQueryParts() {
    return $this->_queryParts;
  }
  function query($iteratorClass = 'GoogleMiniResultIterator') {
    if (!db_table_exists('cache_google_appliance')) {
      $this->cache = FALSE;
    }
    if (!$this->cache) {
      return parent::query($iteratorClass);
    }
    else {
      $cached_result_obj = NULL;
      $cache_key = md5($this
        ->buildQuery());
      $_cached_result_xml = cache_get($cache_key, 'cache_google_appliance');
      $cached_result_xml = $_cached_result_xml->data;
      $google_debug = variable_get('google_appliance_debug', 0);
      if ($cached_result_xml) {
        try {
          $google_results = GoogleMini::resultFactory($cached_result_xml, $iteratorClass);
        } catch (Exception $e) {
          drupal_set_message($e
            ->getMessage(), 'error');
          watchdog('google_appliance', $e
            ->getMessage());
          return FALSE;
        }
        if ($google_debug >= 2) {
          if (function_exists('dpr')) {
            dpr("got cache for {$cache_key}");
          }
        }
        elseif ($google_debug == 1) {
          watchdog('google_appliance', "got cache for !cache_key at !url", array(
            '!cache_key' => $cache_key,
            '!url' => $_GET['q'],
          ));
        }
      }
      else {
        try {
          $google_results = parent::query($iteratorClass);
        } catch (Exception $e) {
          drupal_set_message($e
            ->getMessage(), 'error');
          watchdog('google_appliance', $e
            ->getMessage());
          return FALSE;
        }
        $timeout = variable_get('google_appliance_cache_timeout', 600);

        // 10 minutes by default
        cache_set($cache_key, $google_results->payload
          ->asXML(), 'cache_google_appliance', time() + $timeout);
        $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('google_appliance', "setting cache for !cache_key at !url", array(
            '!cache_key' => $cache_key,
            '!url' => $_GET['q'],
          ));
        }
      }
      return $google_results;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalGoogleMini::$cache property
DrupalGoogleMini::getQueryParts function
DrupalGoogleMini::log function Overrides GoogleMini::log
DrupalGoogleMini::query function Overrides GoogleMini::query
DrupalGoogleMini::__construct function Overrides GoogleMini::__construct
GoogleMini::$baseUrl public property
GoogleMini::$collection public property
GoogleMini::$frontEnd public property
GoogleMini::$_metaDataFilters private property
GoogleMini::$_queryParts protected property
GoogleMini::addMetaDataFilter public function Adds a meta data filter to the query. Currently has limited flexibility. Pass a key as a meta field and values as an array of values to be OR'd together. or you can pass a value as a string to be the only value (for ease of use).
GoogleMini::buildQuery public function Fires the query to google
GoogleMini::getQueryPart public function Helper function, returns a pre-assigned query part.
GoogleMini::resultFactory function
GoogleMini::setDateFilter public function Creates a date filter
GoogleMini::setDateSort public function Sets sorting type (date or relevancy) and direction
GoogleMini::setDomainRestriction public function Adds a site restriction. Useful if just querying by date, as that won't work unless you search for words or at least one other keyword search.
GoogleMini::setInputEncoding public function Set the encoding for data going into the search
GoogleMini::setKeywords public function Set the keywords used for keyword search
GoogleMini::setLanguageFilter public function Sets the languages to be used in the search, if none specified, searches all languages
GoogleMini::setMetaDataRequested public function Set fields to show in results. For all fields, send an asterisk (*)
GoogleMini::setOutputEncoding public function Set the encoding for data coming out of the search
GoogleMini::setPageAndResultsPerPage public function Set page of result set to be shown and sets number of results per page
GoogleMini::setQueryPart public function Helper function, just builds the array for processing, may have validation later.