You are here

public function SarniaController::stash in Sarnia 7

Stash entities from a Solr response. This assumes that items in the response contain all field data, and that all entities in the response should be stashed.

Called from SarniaSolrService::postQuery().

Parameters

array $results: An array of results from Solr, keyed by entity id. Each result is an array of Solr properties.

File

./sarnia.module, line 600

Class

SarniaController
Controller class for Sarnia entities.

Code

public function stash($results) {
  $solr_document_field = '_data';
  foreach (current(field_info_instances($this->entityType)) as $field_name => $instance) {
    $field_info = field_info_field($field_name);
    if ($field_info['type'] == 'sarnia') {
      $solr_document_field = $field_name;
      break;
    }
  }
  $loaded_entities = array();
  foreach ($results as $entity_id => $result) {
    $loaded_entities[$entity_id] = (object) array(
      'type' => $this->entityType,
      $this->idKey => $entity_id,
      $solr_document_field => $result['fields'],
    );
  }

  // Load fields.
  if (!empty($loaded_entities)) {
    $this
      ->attachLoad($loaded_entities);
  }
  $this
    ->cacheSet($loaded_entities);
}