Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function addResults(ResultSetInterface $results)
 {
     // @todo Create getter and setter methods for the search ID.
     $search_id = $results->getQuery()->getOption('search id', '');
     $request = $this->getCurrentRequest();
     if (!isset($this->results[$request])) {
         $this->results[$request] = array($search_id => $results);
     } else {
         // It's not possible to directly assign array values to an array inside of
         // a \SplObjectStorage object. So we have to first retrieve the array,
         // then add the results to it, then store it again.
         $cache = $this->results[$request];
         $cache[$search_id] = $results;
         $this->results[$request] = $cache;
     }
 }
Ejemplo n.º 2
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);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Asserts warnings from a set of search results.
  *
  * @param \Drupal\search_api\Query\ResultSetInterface $results
  *   The results to check.
  * @param array $warnings
  *   (optional) The ignored warnings that should be present, if any.
  * @param string $message
  *   (optional) The message to be displayed with the assertion.
  */
 protected function assertWarnings(ResultSetInterface $results, array $warnings = array(), $message = 'No warnings were displayed.')
 {
     $this->assertEqual($results->getWarnings(), $warnings, $message);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function postprocessSearchResults(ResultSetInterface $results)
 {
     foreach ($this->ignored as $ignored_search_key) {
         $results->addIgnoredSearchKey($ignored_search_key);
     }
 }
Ejemplo n.º 5
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));
}
 /**
  * Asserts that the search results contain the expected IDs.
  *
  * @param ResultSetInterface $result
  *   The search results.
  * @param int[][] $ids
  *   The expected entity IDs, grouped by entity type and with their indexes in
  *   this object's respective array properties as the values.
  */
 protected function assertResults(ResultSetInterface $result, array $expected)
 {
     $results = array_keys($result->getResultItems());
     sort($results);
     $ids = array();
     foreach ($expected as $entity_type => $items) {
         $datasource_id = "entity:{$entity_type}";
         foreach ($items as $i) {
             if ($entity_type == 'user') {
                 $id = $i . ':en';
             } else {
                 $id = $this->{"{$entity_type}s"}[$i]->id() . ':en';
             }
             $ids[] = Utility::createCombinedId($datasource_id, $id);
         }
     }
     sort($ids);
     $this->assertEqual($results, $ids);
 }