You are here

function apachesolr_autocomplete_get_default_context in Apache Solr Autocomplete 7.2

Return the default config for the current context.

Parameters

$context_id: A string identifying the form. For example: apachesolr_search_page:core_search

Return value

array

1 call to apachesolr_autocomplete_get_default_context()
apachesolr_autocomplete_callback in ./apachesolr_autocomplete.module
Callback for url apachesolr_autocomplete/autocomplete.

File

./apachesolr_autocomplete.module, line 130
Alters search forms to suggest terms using Apache Solr using AJAX.

Code

function apachesolr_autocomplete_get_default_context($context_id) {
  $suggestions_to_return = 5;

  // For search pages.
  if (strpos($context_id, 'apachesolr_search_page:') === 0) {
    $search_page_id = substr($context_id, 23);
  }
  else {
    $search_page_id = 'core_search';
  }
  $search_page = apachesolr_search_page_load($search_page_id);
  if (!$search_page) {
    return FALSE;
  }

  // Include any settings provided by apachesolr_search, if defined.
  $params = apachesolr_search_conditions_default($search_page);

  // Set various parameters we'll use in autocomplete.
  $params['facet'] = 'true';
  $params['facet.field'] = array(
    'spell',
  );

  // We ask for $suggestions_to_return * 5 facets, because we want
  // not-too-frequent terms (will be filtered below). 5 is just my best guess.
  $params['facet.limit'] = $suggestions_to_return * 5;
  $params['facet.mincount'] = 1;
  $params['start'] = 0;
  $params['rows'] = 0;
  $solr = apachesolr_get_solr($search_page['env_id']);

  // Return the context.
  $context = array(
    'context_id' => $context_id,
    'search_page' => $search_page,
    'solr' => $solr,
    'apachesolr_params' => $params,
    'engines' => apachesolr_autocomplete_engines(),
    'suggestions_to_return' => 5,
    'spellcheck_suggest' => TRUE,
    'cache_max_age' => 60,
  );
  return $context;
}