You are here

protected function Parser::parseResultCount in Google Search Appliance 8

Parse the count of total results.

Parameters

\SimpleXMLElement $payload: Payload.

\Drupal\google_appliance\SearchResults\ResultSet $response: Response.

1 call to Parser::parseResultCount()
Parser::parseResponse in src/Service/Parser.php
Parses response from GSA.

File

src/Service/Parser.php, line 118

Class

Parser
Defines a class for parsing GSA responses.

Namespace

Drupal\google_appliance\Service

Code

protected function parseResultCount(SimpleXMLElement $payload, ResultSet $response) {
  $response
    ->setTotal((int) $payload->RES->M);

  // C check if there is an result at all ($payload->RES),
  // secure search doesn't provide a value for $payload->RES->M.
  if (isset($payload->RES) && !$response
    ->getTotal()) {
    $response
      ->setTotal((int) $payload->RES['EN']);
    $param_start = $payload
      ->xpath('/GSP/PARAM[@name="start"]');
    $param_num = $payload
      ->xpath('/GSP/PARAM[@name="num"]');
    $request_max_total = (int) $param_start[0]['value'] + (int) $param_num[0]['value'];
    if ($response
      ->getTotal() === $request_max_total) {
      $response
        ->setTotal($response
        ->getTotal() + 1);
    }
  }
}