You are here

function fuzzysearch_build_excerpt in Fuzzy Search 7

Fuzzysearch build excerpt.

1 call to fuzzysearch_build_excerpt()
FuzzysearchExcerpt::postprocessSearchResults in includes/processor_excerpt.inc
Does nothing.

File

./fuzzysearch.module, line 219
Fuzzysearch module.

Code

function fuzzysearch_build_excerpt($entity, $index, $keys) {
  $text = '';

  // Query each matched node for the search ngrams. We use this for fuzzy.
  // highlighting of misspelled words. We do this per node to narrow.
  // the possible false ngrams when a misspelled ngram matches a real one.
  // This could still return some false ngrams, but that's why it's fuzzy.
  $query = fuzzysearch_static_search_query();
  if (empty($query)) {
    return;
  }
  $query
    ->addField('t', 'ngram');
  $query
    ->addField('t', 'word_id');
  $result = $query
    ->execute();
  $clean_grams = array();
  while ($ngram = $result
    ->fetchAssoc()) {
    $clean_grams[$ngram['ngram']][] = $ngram;
  }
  $fuzzy = array_merge(fuzzysearch_get_index_options($index), fuzzysearch_get_excerpt_options($index));
  switch ($index->item_type) {
    case 'node':
      node_build_content($entity);

      // Let removed tags still delimit words.
      $text = str_replace(array(
        '<',
        '>',
      ), array(
        ' <',
        '> ',
      ), render($entity->content));
      $text = strip_tags($text);
      $text = preg_replace('/\\s+/', ' ', $text);
      break;
  }
  return fuzzysearch_process_excerpt($clean_grams, $text, $keys, $fuzzy);
}