public function SearchApiViewsQuery::get_result_wrappers in Search API 7
Returns the according metadata wrappers for the given query results.
This is necessary to support generic entity handlers and plugins with this query backend.
1 call to SearchApiViewsQuery::get_result_wrappers()
- SearchApiViewsQuery::get_result_entities in contrib/
search_api_views/ includes/ query.inc - Returns the according entity objects for the given query results.
File
- contrib/
search_api_views/ includes/ query.inc, line 558 - Contains SearchApiViewsQuery.
Class
- SearchApiViewsQuery
- Views query class using a Search API index as the data source.
Code
public function get_result_wrappers($results, $relationship = NULL, $field = NULL) {
$type = $this->index
->getEntityType() ? $this->index
->getEntityType() : $this->index->item_type;
$wrappers = array();
$load_items = array();
foreach ($results as $row_index => $row) {
if (isset($row->entity)) {
// If this entity isn't load, register it for pre-loading.
if (!is_object($row->entity)) {
$load_items[$row->entity] = $row_index;
}
else {
$wrappers[$row_index] = $this->index
->entityWrapper($row->entity);
}
}
}
// If the results are entities, we pre-load them to make use of a multiple
// load. (Otherwise, each result would be loaded individually.)
if (!empty($load_items)) {
$items = $this->index
->loadItems(array_keys($load_items));
foreach ($items as $id => $item) {
$wrappers[$load_items[$id]] = $this->index
->entityWrapper($item);
}
}
// Apply the relationship, if necessary.
$selector_suffix = '';
if ($field && ($pos = strrpos($field, ':'))) {
$selector_suffix = substr($field, 0, $pos);
}
if ($selector_suffix || $relationship && !empty($this->view->relationship[$relationship])) {
// Use EntityFieldHandlerHelper to compute the correct data selector for
// the relationship.
$handler = (object) array(
'view' => $this->view,
'relationship' => $relationship,
'real_field' => '',
);
$selector = EntityFieldHandlerHelper::construct_property_selector($handler);
$selector .= ($selector ? ':' : '') . $selector_suffix;
list($type, $wrappers) = EntityFieldHandlerHelper::extract_property_multiple($wrappers, $selector);
}
return array(
$type,
$wrappers,
);
}