You are here

protected function Parser::parseOneboxResults in Google Search Appliance 8

Parse onebox results.

Parameters

\SimpleXMLElement $payload: Payload.

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

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

File

src/Service/Parser.php, line 168

Class

Parser
Defines a class for parsing GSA responses.

Namespace

Drupal\google_appliance\Service

Code

protected function parseOneboxResults(SimpleXMLElement $payload, ResultSet $response) {

  // Onebox results.
  // @see https://developers.google.com/search-appliance/documentation/614/oneboxguide#providerresultsschema
  // @see https://developers.google.com/search-appliance/documentation/614/oneboxguide#mergingobs
  foreach ($payload
    ->xpath('//ENTOBRESULTS/OBRES') as $mod) {
    $result_code = empty($mod->resultCode) ? '' : (string) $mod->resultCode;
    if (empty($result_code) || $result_code === 'success') {
      $module_name = (string) $mod['module_name'];
      $onebox = new OneBoxResultSet($module_name, (string) $mod->provider, (string) $mod->title->urlText, (string) $mod->title->urlLink, (string) $mod->IMAGE_SOURCE, $mod->description);
      foreach ($mod
        ->xpath('./MODULE_RESULT') as $res) {
        $result = new OneBoxResult((string) $res->U, (string) $res->Title);
        foreach ($res
          ->xpath('./Field') as $field) {
          $field_name = (string) $field['name'];
          $result
            ->addFieldValue($field_name, (string) $field);
        }
        $onebox
          ->addResult($result);
      }
      $response
        ->addOneBoxResultSet($module_name, $onebox);
    }
  }
}