You are here

function GoogleMini::resultFactory in Google Search Appliance 6.2

Same name and namespace in other branches
  1. 5 GoogleMini.php \GoogleMini::resultFactory()
2 calls to GoogleMini::resultFactory()
DrupalGoogleMini::query in ./DrupalGoogleMini.php
GoogleMini::query in ./GoogleMini.php

File

./GoogleMini.php, line 329

Class

GoogleMini

Code

function resultFactory($resultXML, $className = 'GoogleMiniResultIterator') {
  $results = array();
  libxml_use_internal_errors(TRUE);
  if (!($payload = simplexml_load_string($resultXML))) {
    $errors = array();
    foreach (libxml_get_errors() as $error) {
      $errors[] = $error->message;
    }
    $errors = join(', ', $errors);
    throw new GoogleMiniResultException('There was an error parsing the result XML: ' . $errors);
    return FALSE;
  }
  $totalResults = $payload->RES->M;
  if ($totalResults == 0) {
    if (!$payload->GM) {
      throw new GoogleMiniResultException("No Results found", '1');
    }
  }
  else {
    foreach ($payload
      ->xpath('//R') as $res) {
      $results[] = $res;
    }
  }
  $iterator = new $className($results);
  $iterator->payload = $payload;
  $iterator->time = $payload->TM;
  $iterator->totalResults = $totalResults;
  return $iterator;
}