Apache Solr AJAX
Modules · JavaScript utilities · Performance and scalability · Search · Site navigation · Third-party integration
loganfsmyth - August 24, 2009 - 16:02
The Apache Solr AJAX module AJAXifies Apache Solr Search Integration – if you change your query or filters, you see the new result set instantly – no need to reload the full page.
Plays Nice with Apache Solr Search Integration
With this module, you can still bookmark your searches and click the back button to undo a query or filter change. This module respects all of Apache Solr Search Integration's settings.
Get Started in Three Hooks
<?php
/**
* To successfully configure apachesolr_ajax, you must implement
* hook_apachesolr_ajax_settings(), which must return an array with the
* required keys "content", "blocks", "regions" and the optional key "spinner".
*
* "content" must be the CSS selector for the HTML node in which the page
* content is displayed. In the Zen theme, this is '#content-area'.
*
* "blocks" must be a map between the block keys and the CSS selectors for
* the blocks. Block keys follow the pattern: MODULE_DELTA. In the Zen theme,
* this may be: array('node_0' => '#block-node-0', ...). You need only do this
* for search-related blocks. If you don't know your blocks, run:
*
* <pre>
* $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;
* }
* }
* }
* }
* </pre>
*
* "regions" must be a map between the theme regions and the CSS selectors
* for the regions. In the Zen theme, this may be: array('content_top' =>
* '.region-content-top'). If you don't know your theme's regions, run:
* system_region_list('mytheme');
*
* (Optional) "spinner" is the path to an animated image to be displayed
* while content is loading via AJAX, e.g.: base_path() .
* drupal_get_path('module', 'mymodule') .'/images/spinner.gif'
*/
function mymodule_apachesolr_ajax_settings() {
global $theme;
$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;
}
?><?php
/**
* The apachesolr_ajax module uses Yahoo!'s Browser History Manager to support
* bookmarking and the navigation buttons (back/forward). In Internet Explorer, the
* Browser History Manager requires special markup to appear right after the
* opening <body> tag. Add this markup in two steps:
*
* STEP 1:
* Implement the following function in a theme or module.
*
* STEP 2:
* In page.tpl.php, print $apachesolr_ajax right after the opening <body> tag.
*/
function mytheme_preprocess_page(&$vars, $hook) {
$vars['apachesolr_ajax'] = theme('apachesolr_ajax_yui');
}
?><?php
/**
* If you have a module that defines custom blocks for the apachesolr module, you
* must add the name of that module to apachesolr_ajax's list of search-related
* modules using the following hook. Otherwise, the apachesolr_ajax module will
* not return the HTML for those blocks in its AJAX response.
*/
function mymodule_apachesolr_ajax_modules_alter(&$modules) {
$modules[] = 'mymodule';
}
?>The project is sponsored by Evolving Web of Montreal, Quebec, Canada.
