Completed
Pull Request — develop (#103)
by Sam
03:57 queued 01:42
created

ElasticsearchService::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace Nord\Lumen\Elasticsearch;
2
3
use Elasticsearch\Client;
4
use Nord\Lumen\Elasticsearch\Contracts\ElasticsearchServiceContract;
5
use Nord\Lumen\Elasticsearch\Search\Search;
6
use Nord\Lumen\Elasticsearch\Search\Sort;
7
8
class ElasticsearchService implements ElasticsearchServiceContract
9
{
10
11
    /**
12
     * @var Client
13
     */
14
    private $client;
15
16
17
    /**
18
     * ElasticsearchService constructor.
19
     *
20
     * @param Client $client
21
     */
22
    public function __construct(Client $client)
23
    {
24
        $this->client = $client;
25
    }
26
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function search(array $params = [])
32
    {
33
        return $this->client->search($params);
34
    }
35
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function index(array $params = [])
41
    {
42
        return $this->client->index($params);
43
    }
44
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function reindex(array $params = [])
50
    {
51
        return $this->client->reindex($params);
52
    }
53
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function updateByQuery(array $params = [])
59
    {
60
        return $this->client->updateByQuery($params);
61
    }
62
63
64
    /**
65
     * @inheritdoc
66
     */
67
    public function bulk(array $params = [])
68
    {
69
        return $this->client->bulk($params);
70
    }
71
72
73
    /**
74
     * @inheritdoc
75
     */
76
    public function delete(array $params = [])
77
    {
78
        return $this->client->delete($params);
79
    }
80
81
82
    /**
83
     * @inheritdoc
84
     */
85
    public function deleteByQuery(array $params = [])
86
    {
87
        return $this->client->deleteByQuery($params);
88
    }
89
90
91
    /**
92
     * @inheritdoc
93
     */
94
    public function tasks()
95
    {
96
        return $this->client->tasks();
97
    }
98
99
100
    /**
101
     * @inheritdoc
102
     */
103
    public function create(array $params = [])
104
    {
105
        return $this->client->create($params);
106
    }
107
108
109
    /**
110
     * @inheritdoc
111
     */
112
    public function exists(array $params = [])
113
    {
114
        return $this->client->exists($params);
115
    }
116
117
118
    /**
119
     * @inheritdoc
120
     */
121
    public function indices()
122
    {
123
        return $this->client->indices();
124
    }
125
126
127
    /**
128
     * @inheritdoc
129
     */
130
    public function createSearch()
131
    {
132
        return new Search();
133
    }
134
135
136
    /**
137
     * @inheritdoc
138
     */
139
    public function createSort()
140
    {
141
        return new Sort();
142
    }
143
144
    /**
145
     * @inheritdoc
146
     */
147
    public function execute(Search $search)
148
    {
149
        return $this->search([
150
            'index' => $search->getIndex(),
151
            'type'  => $search->getType(),
152
            'body'  => $search->buildBody(),
153
        ]);
154
    }
155
156
    /**
157
     * @inheritdoc
158
     */
159
    public function count(Search $search): int
160
    {
161
        return $this->client->count([
162
            'index' => $search->getIndex(),
163
            'type'  => $search->getType(),
164
            'body'  => $search->buildBody(),
165
        ])['count'];
166
    }
167
}
168