You are here

public function GoogleMini::buildQuery in Google Search Appliance 6.2

Same name and namespace in other branches
  1. 5 GoogleMini.php \GoogleMini::buildQuery()

Fires the query to google

2 calls to GoogleMini::buildQuery()
DrupalGoogleMini::query in ./DrupalGoogleMini.php
GoogleMini::query in ./GoogleMini.php

File

./GoogleMini.php, line 221

Class

GoogleMini

Code

public function buildQuery() {
  if (!$this->baseUrl || !$this->collection) {
    throw new GoogleMiniQueryException("Required variables (baseUrl or collection) missing", E_WARNING);
  }
  if (count($this->_metaDataFilters)) {
    foreach ($this->_metaDataFilters as $type => $fields) {
      $_metafilter = '';
      foreach ($fields as $field => $mdf) {
        if ($mdf->type == "ANDNEG") {
          foreach ($mdf->values as $value) {
            $metafilter .= '-' . $field . ':' . $value . '.';
          }
        }
        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.

          /***
           * 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) . ").";
          }
        }
        else {
          foreach ($mdf->values as $value) {
            $metafilter .= $field . ':' . $value . '.';
          }
        }
      }
      $metafilter = substr($metafilter, 0, -1);
      $this
        ->setQueryPart($type, $metafilter);
    }
  }
  $this
    ->setQueryPart('output', 'xml_no_dtd');
  $query = $this->baseUrl;
  $query .= "?site=" . $this->collection;
  if ($this->debug) {
    $this
      ->log('Building Query');
    $this
      ->log(var_export($this->_queryParts, 1));
  }
  foreach ($this->_queryParts as $label => $value) {
    $query .= "&{$label}={$value}";
  }
  $this->_query = $query;
  if ($this->debug) {
    $this
      ->log($query);
  }
  return $query;
}