function _google_appliance_search in Google Search Appliance 6.2
Perform the search
1 call to _google_appliance_search()
- google_appliance_search in ./
google_appliance.module - Implementation of hook_search().
File
- ./
google_appliance.module, line 954 - Google Search Appliance (GSA) / Google Mini integration
Code
function _google_appliance_search(&$gm) {
$results = array();
try {
// If you have many searches for the same content
// You can use this setting to keep the GSA from getting hit too often
if ($cache = variable_get('google_appliance_cache_timeout', 0)) {
cache_clear_all(NULL, 'cache_google_appliance');
// Clear expired values.
$gm->cache = TRUE;
// Check the cache when calling $gm->query(). See DrupalGoogleMini.php
}
$result_iterator = $gm
->query();
google_appliance_static_response_cache($result_iterator);
// Store keymatches
google_appliance_cache_data('keymatches', $result_iterator
->getKeyMatches());
// Store synonyms
$synonyms = array();
$keys = urldecode($gm
->getQueryPart('q'));
$base_path = str_replace($keys, '', $_GET['q']);
foreach ($result_iterator
->getSynonyms() as $synonym) {
$url = $base_path . $synonym;
$synonyms[$synonym] = $url;
}
google_appliance_cache_data('synonyms', $synonyms);
// Configure pager
$total_results = (int) $result_iterator->totalResults;
if (GOOGLE_APPLIANCE_TYPE == GOOGLE_APPLIANCE_TYPE_MINI and $total_results > GOOGLE_APPLIANCE_MAX_RESULTS_FOR_MINI) {
$total_results = GOOGLE_APPLIANCE_MAX_RESULTS_FOR_MINI;
}
$limit = $gm
->getQueryPart('num');
$page = $gm
->getQueryPart('start') / $limit;
google_appliance_configure_pager($total_results, $page, $limit);
// Process search results
foreach ($result_iterator as $key => $result) {
if (is_numeric($key)) {
$result_array = theme('google_appliance_search_result_array', $result, $keys);
$results[] = $result_array;
}
}
} catch (Exception $e) {
if ($e
->getCode() > 0) {
google_appliance_static_response_cache($result_iterator);
}
drupal_set_message($e
->getMessage());
return FALSE;
}
return $results;
}