function apachesolr_autocomplete_callback in Apache Solr Autocomplete 7.2
Same name and namespace in other branches
- 6 apachesolr_autocomplete.module \apachesolr_autocomplete_callback()
- 7 apachesolr_autocomplete.module \apachesolr_autocomplete_callback()
Callback for url apachesolr_autocomplete/autocomplete.
Parameters
$context_id: A string identifying the form. For example: apachesolr_search_page:core_search
1 string reference to 'apachesolr_autocomplete_callback'
- apachesolr_autocomplete_menu in ./apachesolr_autocomplete.module 
- Implementation of hook_menu().
File
- ./apachesolr_autocomplete.module, line 178 
- Alters search forms to suggest terms using Apache Solr using AJAX.
Code
function apachesolr_autocomplete_callback($context_id) {
  // Get user entry
  $keys = isset($_GET['term']) ? $_GET['term'] : '';
  if (!$keys) {
    // Exit quickly.
    drupal_json_output(array());
    exit;
  }
  // TODO: Get more user entry, like state of 'retain current filters' and current filters, etc.
  // Get the configuration for the context_id
  $context = apachesolr_autocomplete_get_default_context($context_id);
  // Exit quickly if no context exists.
  if (!$context) {
    drupal_json_output(array());
    exit;
  }
  // TODO: Override the context with any UI-based configuration.
  // TODO: Override the context with user entry, like state of 'retain current filters' and current filters, etc. See .autocomplete(... source:...) on on apachesolr_autocomplete.js
  // Allow other modules to alter the context.
  drupal_alter('apachesolr_autocomplete_context', $context);
  // Run suggestion engines.
  $suggestions = apachesolr_autocomplete_invoke($keys, $context);
  // Output caching headers
  #header("Cache-Control: public, max-age=" . $context['cache_max_age']); // TODO: DEBUG.
  drupal_json_output(array_values($suggestions));
  #print_r($context); // TODO: DEBUG.
  #print_r($suggestions); // TODO: DEBUG.
  exit;
}