function theme_google_appliance_pager in Google Search Appliance 7
Set up Drupal pager for pagination of GSA-provided search results.
We're not paging druppal-database content in this version, so the core pager is not aware of the page-able results provided by the GSA ... We're only requesting one page of the results at a time, but we get enough stats from that query to fake the pager, and provide a familiar interface.
1 theme call to theme_google_appliance_pager()
- template_preprocess_google_appliance_results in theme/
google_appliance.theme.inc - Preprocess google-search-appliance-results.tpl.php (results page).
File
- theme/
google_appliance.theme.inc, line 442 - theme registry and preprocess functions for the default templates
Code
function theme_google_appliance_pager(&$vars) {
// Grab module settings.
$settings = _google_appliance_get_settings();
// Globals required to manually configure the pager.
global $pager_page_array, $pager_total, $pager_total_items;
$control_tags = array();
// default labels
$element = 0;
$limit = $settings['results_per_page'];
// Total # of pages in list.
$total_pages = ceil($vars['total_results_count'] / $limit);
/**
* NOTE: the total results count from the GSA is unreliable. The docs
* state that it is an *approximation*, but if you click around on
* enough searches, you'll find that it's off by a considerable amount -
* enough to break the math used to create pager links. It's not all that
* noticeable unless you click on the "last" link in the pager, and
* notice that in some searches, the last page is paginated at a number
* less than was previously viewable when the first page of results came
* up on the initial search view.
*
* The problem is rooted in public vs. access-controlled indexing.
* @see groups.google.com/group/Google-Search-Appliance-Help/browse_thread/thread/019b77fb3e7950c7
* Access-controled results are counted before we know if we can actually
* view it. Device configuration can help.
*
* @TODO: perhaps a better solution is to just query the device for the
* first X (up to 1000) results and cache them locally.
*/
// Manually configure (fake) the pager.
$page = isset($_GET['page']) ? check_plain($_GET['page']) : 0;
// Convert page id to array.
$pager_page_array = explode(',', $page);
// Set the total results.
$pager_total_items[$element] = (int) $vars['total_results_count'];
// Set the total # of pages.
$pager_total[$element] = ceil($pager_total_items[$element] / $limit);
$pager_page_array[$element] = max(0, min((int) $pager_page_array[$element], (int) $pager_total[$element] - 1));
return theme('pager');
}