/** * Takes either an array or a Result object form a search and constructs * a document representing an entity in a elastic search type, * * @param array|Elastica\Result $data An array or Result object that * represents an Elasticsearch document * @param array $options An array of options to set the state of the * document */ public function __construct($data = [], $options = []) { if ($data instanceof Result) { $options['result'] = $data; $id = $data->getId(); $data = $data->getData(); if ($id !== []) { $data['id'] = $id; } } $options += ['useSetters' => true, 'markClean' => false, 'markNew' => null, 'guard' => false, 'source' => null, 'result' => null]; if (!empty($options['source'])) { $this->source($options['source']); } if ($options['markNew'] !== null) { $this->isNew($options['markNew']); } if ($options['result'] !== null) { $this->_result = $options['result']; } if (!empty($data) && $options['markClean'] && !$options['useSetters']) { $this->_properties = $data; return; } if (!empty($data)) { $this->set($data, ['setter' => $options['useSetters'], 'guard' => $options['guard']]); } if ($options['markClean']) { $this->clean(); } }
/** * {@inheritDoc} */ public function toModel(Result $result, Model $model) { $exclude = ['location', 'full_address']; $filtered = array_diff_key($result->getSource(), array_flip($exclude)); $model->exists = true; $model->id = $result->getId(); $model->fill($filtered); return $model; }
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; }
/** * @param Result $articleObject * @return string */ private function generateArticleUrl(Result $articleObject) { $source = $articleObject->getSource(); if (!isset($source['issue']['id'])) { return false; } return $this->router->generate('ojs_article_page', ['slug' => $source['journal']['slug'], 'article_id' => $articleObject->getId(), 'issue_id' => $source['issue']['id'], 'publisher' => $source['journal']['publisher']['slug']], true); }
/** * Return the id of the * * @return string */ public function getId() { return $this->elasticaResult->getId(); }
/** * Wrapper around formatBean based on Result * * @param \RestService $api * @param Result $result * * @return array */ protected function formatBeanFromResult(\RestService $api, array $args, \Elastica\Result $result, SugarBean $bean) { // pass in field list from available data fields on result if (empty($args['fields'])) { $args['fields'] = array_keys($result->getSource()); } $bean->retrieve($result->getId()); return $this->formatBean($api, $args, $bean); }
/** * {@inheritDoc} */ public function toModel(Result $result, Model $model) { $model = $model->find($result->getId()); return $model; }