On a recent Drupal project, the design for the search results page called for displaying the total number of results found in the page title: 120 results found for the term "school" I was using Apache Solr for the search solution, and to override the page title, I implement THEMENAME_preprocess_page() in template.php:
<?phpfunction MYTHEME_preprocess_page(&$vars) {
if(arg(1) == 'apachesolr_search') {
if (apachesolr_has_searched() && ($response = apachesolr_static_response_cache())) {
$query = apachesolr_current_query();
$keywords = $query->get_query_basic();
$num_found = $response->response->numFound;
$vars['title'] = $num_found.' results for the term "'.check_plain($keywords).'"';
}
}
} ?>If you use the Context module, set up a context called "search" and use that condition instead:
<?phpfunction MYTHEME_preprocess_page(&$vars) {
$contexts = context_active_contexts();
if(array_key_exists('search', $contexts)) {
if (apachesolr_has_searched() && ($response = apachesolr_static_response_cache())) {
$query = apachesolr_current_query();
$keywords = $query->get_query_basic();
$num_found = $response->response->numFound;
$vars['title'] = $num_found.' results for the term "'.check_plain($keywords).'"';
}
}
} ?>http://beyrent.net/blog/2011/08/getting-total-number-results-found-apache-solr-searches

0 comments:
Post a Comment