Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function postprocessSearchResults(ResultSetInterface $results)
 {
     if (!$results->getResultCount() || !($keys = $this->getKeywords($results->getQuery()))) {
         return;
     }
     $result_items = $results->getResultItems();
     if ($this->configuration['excerpt']) {
         $this->addExcerpts($result_items, $keys);
     }
     if ($this->configuration['highlight'] != 'never') {
         $highlighted_fields = $this->highlightFields($result_items, $keys);
         if ($highlighted_fields) {
             // Maybe the backend or some other processor has already set highlighted
             // field values.
             foreach ($results->getExtraData('highlighted_fields', array()) as $item_id => $old_highlighting) {
                 $highlighted_fields += array($item_id => array());
                 $highlighted_fields[$item_id] += $old_highlighting;
             }
             $results->setExtraData('highlighted_fields', $highlighted_fields);
         }
     }
 }
Exemple #2
0
/**
 * Alter a search query's result set.
 *
 * The hook is invoked after all enabled processors have postprocessed the
 * results.
 *
 * @param \Drupal\search_api\Query\ResultSetInterface $results
 *   The search results to alter.
 */
function hook_search_api_results_alter(\Drupal\search_api\Query\ResultSetInterface &$results) {
  $results->setExtraData('example_hook_invoked', microtime(TRUE));
}