public function newFromHitBuilder($hit = array())
{
$key_name = $this->getKeyName();
$attributes = $hit['_source'];
if (isset($hit['_id'])) {
$attributes[$key_name] = is_numeric($hit['_id']) ? intval($hit['_id']) : $hit['_id'];
}
// Add fields to attributes
if (isset($hit['fields'])) {
foreach ($hit['fields'] as $key => $value) {
$attributes[$key] = $value;
}
}
$instance = $this::newFromBuilderRecursive($this, $attributes);
// In addition to setting the attributes
// from the index, we will set the score as well.
$instance->documentScore = $hit['_score'];
// This is now a model created
// from an Elasticsearch document.
$instance->isDocument = true;
// Set our document version if it's
if (isset($hit['_version'])) {
$instance->documentVersion = $hit['_version'];
}
return $instance;
}