Skip to content

Instantly share code, notes, and snippets.

@hoffigk
Created October 30, 2013 10:21
Show Gist options
  • Save hoffigk/7230240 to your computer and use it in GitHub Desktop.
Save hoffigk/7230240 to your computer and use it in GitHub Desktop.
<?php
/**
* Loads all data into the results object (initialisation)
*
* @param \Elastica\Response $response Response object
*/
protected function _init(Response $response)
{
$this->_response = $response;
$result = $response->getData();
$this->_totalHits = isset($result['hits']['total']) ? $result['hits']['total'] : 0;
$this->_maxScore = isset($result['hits']['max_score']) ? $result['hits']['max_score'] : 0;
$this->_took = isset($result['took']) ? $result['took'] : 0;
$this->_timedOut = !empty($result['timed_out']);
if (isset($result['hits']['hits'])) {
foreach ($result['hits']['hits'] as $hit) {
$this->_results[] = new Result($hit);
}
}
if (isset($result['suggest'])) {
foreach($result['suggest'] as $suggestName => $suggest) {
if(isset($suggest[0]['options']) && count($suggest[0]['options'])>0) {
$this->_suggests[$suggestName] = $suggest[0];
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment