1 | <?php |
||
11 | class ElasticsearchDAL implements IDAL |
||
12 | { |
||
13 | protected $model; |
||
14 | protected $client; |
||
15 | protected $logger; |
||
16 | |||
17 | 16 | public function __construct(ElasticsearchModel $model, Client $client, LoggerInterface $logger = null) |
|
23 | |||
24 | public function getModel() |
||
28 | |||
29 | public function get($id, array $options = []) |
||
30 | { |
||
31 | $params = $this->model->getPath()->toArray(); |
||
32 | |||
33 | if (!empty($options['columns'])) { |
||
34 | $params['_source'] = $options['columns']; |
||
35 | } |
||
36 | |||
37 | if (!empty($options['parent'])) { |
||
38 | $params['parent'] = $options['parent']; |
||
39 | } |
||
40 | |||
41 | $response = $this->client->get($params); |
||
42 | |||
43 | return $this->model->fillByResponse($response); |
||
44 | } |
||
45 | |||
46 | 12 | public function put(array $columns = ['*']) |
|
47 | { |
||
48 | 12 | $params = $this->getParams(); |
|
49 | |||
50 | 12 | if (!$this->model->_exist || $columns == ['*']) { |
|
51 | 12 | if (!$params['id']) { |
|
52 | unset($params['id']); |
||
53 | } |
||
54 | |||
55 | 12 | $params['body'] = $this->model->toArray(); |
|
56 | |||
57 | 12 | $response = $this->client->index($params); |
|
58 | 12 | } else { |
|
59 | $params['body'] = [ |
||
60 | 'doc' => array_only($this->model->toArray(), $columns) |
||
61 | ]; |
||
62 | |||
63 | $response = $this->client->update($params); |
||
64 | } |
||
65 | |||
66 | 12 | $this->model->setId($response['_id']); |
|
67 | |||
68 | 12 | return $this->model->getId(); |
|
69 | } |
||
70 | |||
71 | 2 | public function delete() |
|
75 | |||
76 | 12 | protected function getParams() |
|
86 | |||
87 | public function search(array $query) |
||
88 | { |
||
126 | } |
||
127 |