You are here

function hook_google_appliance_results_alter in Google Search Appliance 7

Alter Google Search Appliance results.

This hook is invoked after the search appliance returns with a response and the Google Search Appliance module does its basic parsing.

Use this to make result alterations that are inappropriate at the theme level.

Parameters

$results: The search results, represented as a multi-dimensional associative array.

$payload: The XML returned by the search appliance as a SimpleXMLElement object. Although this is alterable, it's unlikely you will want to make changes to the XML payload.

See also

google_appliance_parse_device_response_xml()

Related topics

1 invocation of hook_google_appliance_results_alter()
google_appliance_parse_device_response_xml in ./google_appliance.module
Parse the response from the Google Search Appliance device into a php array

File

./google_appliance.api.php, line 96
This file contains no working PHP code; it exists to provide additional documentation for doxygen as well as to document hooks in the standard Drupal manner.

Code

function hook_google_appliance_results_alter(&$results, &$payload) {

  // Simple example: alter all titles returned in the result set.
  foreach ($results['entry'] as &$result) {
    $result['title'] = str_replace('foo', 'bar', $result['title']);
  }

  // Advanced example: parse and return onebox results from the payload.
  foreach ($payload
    ->xpath('//OBRES') as $onebox) {

    // Code to parse each onebox here.
    $ob_return = array(
      'foo' => 'bar',
      'baz' => array(),
    );

    // Add the onebox to the results array.
    $results['oneboxes'][] = $ob_return;
  }
}