Get Started in Two Steps

Last updated on
30 April 2025

hook_apachesolr_ajax_settings()

You must implement hook_apachesolr_ajax_settings(), which must return an array with the keys "content", "blocks", "regions" and, optionally, "spinner". The function will look roughly like:

function mymodule_apachesolr_ajax_settings() {
  $settings = array(
    'content' => 'CSS_SELECTOR',
    'regions' => array(
      'REGION' => 'CSS_SELECTOR',
      ...
    ),
    'blocks' => array(
      'MODULE_DELTA' => 'CSS_SELECTOR',
      ...
    ),
  );
  return $settings;
}

Let's go over the keys one by one:

"content"
Set this to the CSS selector for the HTML node in which the page content is displayed. In the Zen theme, "content" should be set to '#content-area'.
"blocks"
A map between block keys and their CSS selectors. Block keys follow the pattern MODULE_DELTA: for example, node_0. In the Zen theme, "blocks" may be set to: array('node_0' => '#block-node-0', ...). You only need to map your search-related blocks, because only search-related blocks need to be updated via AJAX. If you don't know your block keys, run the following code to get a list of block keys:
$modules = apachesolr_ajax_modules();
foreach ($modules as $module) {
  if (module_exists($module)) {
    if ($list = module_invoke($module, 'block', 'list')) {
      foreach (array_keys($list) as $delta) {
        print $module .'_'. $delta;
      }
    }
  }
}
"regions"
A map between theme regions and their CSS selectors. In the Zen theme, "regions" may be set to: array('content_top' => '.region-content-top', ...). If you don't know your theme's regions, run the following code to get a list of your theme's regions:
system_region_list('MYTHEME');
"spinner" (Optional, but recommended)
Set this to the path of the image to be displayed while content is loading via AJAX, e.g.: base_path() . path_to_theme() .'/images/spinner.gif'

Putting it all together, your hook_apachesolr_ajax_settings() may look like:

function mymodule_apachesolr_ajax_settings() {
  $settings = array(
    'content' => '#content-area',
    'regions' => array(
      'sidebar_first' => '.region-sidebar-first .section',
      'sidebar_second' => '.region-sidebar-second .section',
      'content_top' => '.region-content-top',
      'content_bottom' => '.region-content-bottom',
    ),
  );

  $modules = apachesolr_ajax_modules();
  foreach ($modules as $module) {
    if (module_exists($module)) {
      if ($list = module_invoke($module, 'block', 'list')) {
        foreach (array_keys($list) as $delta) {
          $settings['blocks'][$module .'_'. $delta] = '#block-'. $module .'-'. $delta;
        }
      }
    }
  }

  return $settings;
}

page.tpl.php

This module uses Yahoo!'s Browser History Manager to support bookmarking and the back/forward buttons. In Internet Explorer, you need to add special markup to your page for the Browser History Manager to work. In page.tpl.php, print $apachesolr_ajax right after the opening <body> tag.

Don't forget to hide the <iframe> using the following CSS code:

#yui-history-iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  visibility: hidden;
}

Help improve this page

Page status: Not set

You can: