You are here

function theme_apachesolr_autocomplete_highlight in Apache Solr Autocomplete 6

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

Themes each returned suggestion.

File

./apachesolr_autocomplete.module, line 157
Alters search forms to suggest terms using Apache Solr using AJAX. Thanks to robertDouglass who contributed some of the code.

Code

function theme_apachesolr_autocomplete_highlight($suggestion, $show_counts = TRUE) {
  static $first = true;
  $keys = $suggestion['keys'];
  $suggestion_string = $suggestion['suggestion'];
  $count = $suggestion['count'];
  $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;
}