public function SearchApiHighlight::postprocessSearchResults in Search API 7
Does nothing.
Overrides SearchApiAbstractProcessor::postprocessSearchResults
File
- includes/
processor_highlight.inc, line 138 - Contains the SearchApiHighlight class.
Class
- SearchApiHighlight
- Processor for highlighting search results.
Code
public function postprocessSearchResults(array &$response, SearchApiQuery $query) {
if (empty($response['results']) || !($keys = $this
->getKeywords($query))) {
return;
}
$fulltext_fields = $this->index
->getFulltextFields();
if (!empty($this->options['exclude_fields'])) {
$fulltext_fields = drupal_map_assoc($fulltext_fields);
foreach ($this->options['exclude_fields'] as $field) {
unset($fulltext_fields[$field]);
}
}
foreach ($response['results'] as $id => &$result) {
if ($this->options['excerpt']) {
$text = array();
$fields = $this
->getFulltextFields($response['results'], $id, $fulltext_fields);
foreach ($fields as $data) {
if (is_array($data)) {
$text = array_merge($text, $data);
}
else {
$text[] = $data;
}
}
$result['excerpt'] = $this
->createExcerpt($this
->flattenArrayValues($text), $keys);
}
if ($this->options['highlight'] != 'never') {
$fields = $this
->getFulltextFields($response['results'], $id, $fulltext_fields, $this->options['highlight'] == 'always');
foreach ($fields as $field => $data) {
$result['fields'][$field] = array(
'#sanitize_callback' => FALSE,
);
if (is_array($data)) {
foreach ($data as $i => $text) {
$result['fields'][$field]['#value'][$i] = $this
->highlightField($text, $keys);
}
}
else {
$result['fields'][$field]['#value'] = $this
->highlightField($data, $keys);
}
}
}
}
}