You are here

public function SearchApiViewsQuery::get_result_entities in Search API 7

Returns the according entity objects for the given query results.

This is necessary to support generic entity handlers and plugins with this query backend.

If the current query isn't based on an entity type, the method will return an empty array.

Overrides views_plugin_query::get_result_entities

File

contrib/search_api_views/includes/query.inc, line 529
Contains SearchApiViewsQuery.

Class

SearchApiViewsQuery
Views query class using a Search API index as the data source.

Code

public function get_result_entities($results, $relationship = NULL, $field = NULL) {
  list($type, $wrappers) = $this
    ->get_result_wrappers($results, $relationship, $field);
  $return = array();
  foreach ($wrappers as $i => $wrapper) {
    try {

      // Get the entity ID beforehand for possible watchdog messages.
      $id = $wrapper
        ->value(array(
        'identifier' => TRUE,
      ));

      // Only add results that exist.
      if ($entity = $wrapper
        ->value()) {
        $return[$i] = $entity;
      }
      else {
        watchdog('search_api_views', 'The search index returned a reference to an entity with ID @id, which does not exist in the database. Your index may be out of sync and should be rebuilt.', array(
          '@id' => $id,
        ), WATCHDOG_ERROR);
      }
    } catch (EntityMetadataWrapperException $e) {
      watchdog_exception('search_api_views', $e, "%type while trying to load search result entity with ID @id: !message in %function (line %line of %file).", array(
        '@id' => $id,
      ), WATCHDOG_ERROR);
    }
  }
  return array(
    $type,
    $return,
  );
}