/** * Returns the explanation array for this document as returned from ElasticSearch. * * If this is a new document, or the query used to create it did not ask for * explanation, this function will return an empty array. * * @return array */ public function explanation() { if ($this->_result) { return $this->_result->getExplanation(); } return []; }
protected function formatResult(Result $result, $showField, $showSource, $showId, $explain) { $source = $result->getSource(); if ($showField) { $toString = isset($source[$showField]) ? $source[$showField] : '-'; } else { $toString = reset($source); } $string = sprintf('[%0.2f] %s', $result->getScore(), var_export($toString, true)); if ($showSource) { $string = sprintf('%s %s', $string, json_encode($source)); } if ($showId) { $string = sprintf('{%s} %s', $result->getId(), $string); } if ($explain) { $string = sprintf('%s %s', $string, json_encode($result->getExplanation())); } return $string; }