You are here

function theme_apachesolr_autocomplete_highlight in Apache Solr Autocomplete 7

Same name and namespace in other branches
  1. 6 apachesolr_autocomplete.module \theme_apachesolr_autocomplete_highlight()
  2. 7.2 apachesolr_autocomplete.module \theme_apachesolr_autocomplete_highlight()

Themes each returned suggestion.

File

./apachesolr_autocomplete.module, line 252
Alters search forms to suggest terms using Apache Solr using AJAX. Thanks to: robertDouglass who contributed some of the code. sch4lly for contributing to D7 version

Code

function theme_apachesolr_autocomplete_highlight($variables) {
  static $first = true;
  $keys = $variables['suggestion']['keys'];
  $suggestion_string = $variables['suggestion']['suggestion'];
  $count = $variables['suggestion']['count'];
  $show_counts = $variables['show_counts'];
  $html = '';
  $html .= '<div class="apachesolr_autocomplete suggestion">';
  $html .= '<strong>' . drupal_substr($suggestion_string, 0, strlen($keys)) . '</strong>' . drupal_substr($suggestion_string, strlen($keys));
  $html .= '</div>';
  if ($count && $show_counts) {
    if ($first) {
      $html .= "<div class='apachesolr_autocomplete message' style='float:right'>";
      $html .= t('!count results', array(
        '!count' => $count,
      ));
      $html .= "</div><br style='clear:both'>";
      $first = false;
    }
    else {
      $html .= "<div class='apachesolr_autocomplete message count'>{$count}</div><br style='clear:both'>";
    }
  }
  return $html;
}