You are here

function apachesolr_search_custom_page in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 apachesolr_search.pages.inc \apachesolr_search_custom_page()
  2. 6.3 apachesolr_search.pages.inc \apachesolr_search_custom_page()

Returns search results on user defined search pages.

1 string reference to 'apachesolr_search_custom_page'
apachesolr_search_menu_alter in ./apachesolr_search.module

File

./apachesolr_search.pages.inc, line 11
Provides the page callback for user defined search pages.

Code

function apachesolr_search_custom_page($page_id, $keys = '', $path_replacer = NULL) {
  $search_page = apachesolr_search_page_load($page_id);
  if (empty($search_page)) {
    drupal_set_message(t('This search page cannot be found'), 'error');
    return drupal_not_found();
  }

  // Activate the page context, if the module is enabled.
  if (module_exists('context') && ($plugin = context_get_plugin('condition', 'apachesolr_page'))) {
    $plugin
      ->execute($search_page);
  }

  // Add our replacement value in the conditions array
  if (!empty($path_replacer)) {
    $search_page['settings']['apachesolr_search_path_replacer'] = $path_replacer;
  }

  // Replace dynamic path with current path
  $search_page['search_path'] = str_replace('%', $path_replacer, $search_page['search_path']);

  // Retrieve the conditions that apply to this page
  $conditions = apachesolr_search_conditions_default($search_page);

  // Process our keys so they are clean
  $keys = rawurldecode($keys);

  // Initiate our build array
  $build = array();

  // Add a custom search form if required
  if (!empty($search_page['settings']['apachesolr_search_search_box'])) {

    // Adds the search form to the page.
    $build['search_form'] = drupal_get_form('apachesolr_search_custom_page_search_form', $search_page, $keys, $conditions);
  }

  // Retrieve the results of the search
  $results = apachesolr_search_search_results($keys, $conditions, $search_page);

  // Build our page and allow modification.
  $build_results = apachesolr_search_search_page_custom($results, $search_page, $build);
  return $build_results;
}