function google_appliance_get_clusters in Google Search Appliance 7
get related search via the Google Search Appliance clustering service
Return value
themed list of links
1 call to google_appliance_get_clusters()
- google_appliance_block_view in ./
google_appliance.module - Implements hook_block_view().
File
- ./
google_appliance.module, line 784 - Google Appliance module enables searching via a dedicated Google Search Appliance hardware device. See README.txt and the help page at admin/help/google_appliance.
Code
function google_appliance_get_clusters() {
// grab module settings
$settings = _google_appliance_get_settings();
// get the search query
$query_pos = substr_count($settings['drupal_path'], '/') + 1;
$search_query = urldecode(arg($query_pos));
$cluster_content = NULL;
// perform POST to acquire the clusters block
$clusterQueryURL = check_plain($settings['hostname'] . '/cluster');
$clusterQueryParams = array(
'q' => check_plain($search_query),
'btnG' => 'Google+Search',
'access' => 'p',
'entqr' => '0',
'ud' => '1',
'sort' => 'date:D:L:d1',
'output' => 'xml_no_dtd',
'oe' => 'utf8',
'ie' => 'utf8',
'site' => check_plain($settings['collection']),
'client' => check_plain($settings['frontend']),
);
// Alter request according to language filter settings.
if (module_exists('locale') && $settings['language_filter_toggle']) {
$clusterQueryParams['lr'] = _google_appliance_get_lr($settings['language_filter_options']);
}
// cURL request for the clusters produces JSON result
$gsa_clusters_json = _curl_post($clusterQueryURL, $clusterQueryParams);
if (!$gsa_clusters_json['is_error']) {
// no error -> get the clusters
$clusters = json_decode($gsa_clusters_json['response'], TRUE);
if (isset($clusters['clusters'][0])) {
// Build the link list.
$cluster_list_items = array();
foreach ($clusters['clusters'][0]['clusters'] as $cluster) {
array_push($cluster_list_items, l($cluster['label'], $settings['drupal_path'] . '/' . $cluster['label']));
}
// Create theme-friendly list of links render array.
$cluster_list = array(
'#theme' => 'item_list',
'#items' => $cluster_list_items,
'#title' => NULL,
'#type' => 'ul',
'#attributes' => array(),
);
// Allow implementation of hook_google_appliance_cluster_list_alter() by
// other modules.
drupal_alter('google_appliance_cluster_list', $cluster_list, $cluster_results);
$cluster_content = drupal_render($cluster_list);
}
}
return $cluster_content;
}