You are here

function apachesolr_search_preprocess_apachesolr_search_snippets in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 apachesolr_search.module \apachesolr_search_preprocess_apachesolr_search_snippets()
  2. 7 apachesolr_search.module \apachesolr_search_preprocess_apachesolr_search_snippets()

Preprocess function for theme_apachesolr_search_snippets().

File

./apachesolr_search.module, line 1691
Provides a content search implementation for node content for use with the Apache Solr search application.

Code

function apachesolr_search_preprocess_apachesolr_search_snippets(&$vars) {

  // Flatten the multidimensional array of snippets into a one-dimensional,
  // ordered array.
  $vars['flattened_snippets'] = array();
  $snippets = $vars['snippets'];
  if (is_array($snippets)) {

    // Prioritize the 'content' and 'teaser' keys if they are present.
    foreach (array(
      'content',
      'teaser',
    ) as $key) {
      if (isset($snippets[$key])) {
        $vars['flattened_snippets'] = array_merge($vars['flattened_snippets'], $snippets[$key]);
        unset($snippets[$key]);
      }
    }

    // Add any remaining snippets from the array. Each snippet can either be a
    // string or an array itself; see apachesolr_search_process_response().
    foreach ($snippets as $snippet) {
      $vars['flattened_snippets'] = array_merge($vars['flattened_snippets'], is_array($snippet) ? $snippet : array(
        $snippet,
      ));
    }
  }

  // Ensure unique search snippets.
  $vars['flattened_snippets'] = array_unique($vars['flattened_snippets']);
}