Issues (3641)

Search/src/Spryker/Client/Search/SearchClient.php (1 issue)

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace Spryker\Client\Search;
9
10
use Generated\Shared\Transfer\SearchDocumentTransfer;
11
use Spryker\Client\Kernel\AbstractClient;
12
use Spryker\Client\SearchExtension\Dependency\Plugin\QueryInterface;
13
14
/**
15
 * @method \Spryker\Client\Search\SearchFactory getFactory()
16
 */
17
class SearchClient extends AbstractClient implements SearchClientInterface
18
{
19
    /**
20
     * {@inheritDoc}
21
     *
22
     * @api
23
     *
24
     * @throws \Exception
25
     *
26
     * @return void
27
     */
28
    public function checkConnection()
29
    {
30
        $connectionAdapterPlugins = $this->getFactory()->getClientAdapterPlugins();
31
32
        if (!$connectionAdapterPlugins) {
33
            $this->getFactory()
34
                ->getElasticsearchClient()
35
                ->getStatus()
36
                ->getData();
37
38
            return;
39
        }
40
41
        $this->getFactory()
42
            ->createConnectionDelegator()
43
            ->checkConnection();
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     *
49
     * @api
50
     *
51
     * @param \Spryker\Client\SearchExtension\Dependency\Plugin\QueryInterface $searchQuery
52
     * @param array<\Spryker\Client\SearchExtension\Dependency\Plugin\QueryExpanderPluginInterface> $searchQueryExpanders
53
     * @param array<string, mixed> $requestParameters
54
     *
55
     * @return \Spryker\Client\SearchExtension\Dependency\Plugin\QueryInterface
56
     */
57
    public function expandQuery(QueryInterface $searchQuery, array $searchQueryExpanders, array $requestParameters = [])
58
    {
59
        foreach ($searchQueryExpanders as $searchQueryExpander) {
60
            $searchQuery = $searchQueryExpander->expandQuery($searchQuery, $requestParameters);
61
        }
62
63
        return $searchQuery;
64
    }
65
66
    /**
67
     * {@inheritDoc}
68
     *
69
     * @api
70
     *
71
     * @param \Spryker\Client\SearchExtension\Dependency\Plugin\QueryInterface $searchQuery
72
     * @param array<\Spryker\Client\SearchExtension\Dependency\Plugin\ResultFormatterPluginInterface> $resultFormatters
73
     * @param array<mixed> $requestParameters
74
     *
75
     * @return \Elastica\ResultSet|mixed|array (@deprecated Only mixed will be supported with the next major)
76
     */
77
    public function search(QueryInterface $searchQuery, array $resultFormatters = [], array $requestParameters = [])
78
    {
79
        return $this
80
            ->getFactory()
81
            ->createElasticsearchSearchHandler()
82
            ->search($searchQuery, $resultFormatters, $requestParameters);
83
    }
84
85
    /**
86
     * {@inheritDoc}
87
     *
88
     * @api
89
     *
90
     * @param string $searchString
91
     * @param int|null $limit
92
     * @param int|null $offset
93
     *
94
     * @return \Elastica\ResultSet|mixed|array (@deprecated Only mixed will be supported with the next major)
95
     */
96
    public function searchKeys($searchString, $limit = null, $offset = null)
97
    {
98
        $query = $this
99
            ->getFactory()
100
            ->createSearchKeysQuery($searchString, $limit, $offset);
101
102
        return $this->search($query);
103
    }
104
105
    /**
106
     * {@inheritDoc}
107
     *
108
     * @api
109
     *
110
     * @param \Generated\Shared\Transfer\SearchDocumentTransfer $searchDocumentTransfer
111
     *
112
     * @return mixed
113
     */
114
    public function readDocument(SearchDocumentTransfer $searchDocumentTransfer)
115
    {
116
        return $this->getFactory()->createSearchDelegator()->readDocument($searchDocumentTransfer);
117
    }
118
119
    /**
120
     * {@inheritDoc}
121
     *
122
     * @api
123
     *
124
     * @param \Generated\Shared\Transfer\SearchDocumentTransfer $searchDocumentTransfer
125
     *
126
     * @return bool
127
     */
128
    public function writeDocument(SearchDocumentTransfer $searchDocumentTransfer): bool
129
    {
130
        return $this->getFactory()->createSearchDelegator()->writeDocument($searchDocumentTransfer);
131
    }
132
133
    /**
134
     * {@inheritDoc}
135
     *
136
     * @api
137
     *
138
     * @param array<\Generated\Shared\Transfer\SearchDocumentTransfer> $searchDocumentTransfers
139
     *
140
     * @return bool
141
     */
142
    public function writeDocuments(array $searchDocumentTransfers): bool
143
    {
144
        return $this->getFactory()->createSearchDelegator()->writeDocuments($searchDocumentTransfers);
145
    }
146
147
    /**
148
     * {@inheritDoc}
149
     *
150
     * @api
151
     *
152
     * @param \Generated\Shared\Transfer\SearchDocumentTransfer $searchDocumentTransfer
153
     *
154
     * @return bool
155
     */
156
    public function deleteDocument(SearchDocumentTransfer $searchDocumentTransfer): bool
157
    {
158
        return $this
159
            ->getFactory()
160
            ->createSearchDelegator()
161
            ->deleteDocument($searchDocumentTransfer);
162
    }
163
164
    /**
165
     * {@inheritDoc}
166
     *
167
     * @api
168
     *
169
     * @param array<\Generated\Shared\Transfer\SearchDocumentTransfer> $searchDocumentTransfers
170
     *
171
     * @return bool
172
     */
173
    public function deleteDocuments(array $searchDocumentTransfers): bool
174
    {
175
        return $this
176
            ->getFactory()
177
            ->createSearchDelegator()
178
            ->deleteDocuments($searchDocumentTransfers);
179
    }
180
181
    /**
182
     * {@inheritDoc}
183
     *
184
     * @api
185
     *
186
     * @deprecated Will be removed without replacement. This functionality is obsolete and should not be used.
187
     *
188
     * @return \Spryker\Client\Search\Dependency\Plugin\SearchConfigInterface
189
     */
190
    public function getSearchConfig()
191
    {
192
        return $this->getFactory()->getSearchConfig();
193
    }
194
195
    /**
196
     * {@inheritDoc}
197
     *
198
     * @api
199
     *
200
     * @deprecated Will be removed without replacement.
201
     *
202
     * @param string $searchString
203
     * @param int|null $limit
204
     * @param int|null $offset
205
     *
206
     * @return \Elastica\ResultSet|mixed|array (@deprecated Only mixed will be supported with the next major)
207
     */
208
    public function searchQueryString($searchString, $limit = null, $offset = null)
209
    {
210
        $query = $this
211
            ->getFactory()
212
            ->createSearchStringQuery($searchString, $limit, $offset);
213
214
        return $this->search($query);
0 ignored issues
show
Deprecated Code introduced by
The function Spryker\Client\Search\SearchClient::search() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

214
        return /** @scrutinizer ignore-deprecated */ $this->search($query);
Loading history...
215
    }
216
217
    /**
218
     * {@inheritDoc}
219
     *
220
     * @api
221
     *
222
     * @deprecated Use {@link \Spryker\Client\Search\SearchClient::readDocument()} instead.
223
     *
224
     * @param string $key
225
     * @param string|null $typeName
226
     * @param string|null $indexName
227
     *
228
     * @return mixed
229
     */
230
    public function read($key, $typeName = null, $indexName = null)
231
    {
232
        return $this
233
            ->getFactory()
234
            ->createReader()
235
            ->read($key, $typeName, $indexName);
236
    }
237
238
    /**
239
     * {@inheritDoc}
240
     *
241
     * @api
242
     *
243
     * @deprecated Use {@link \Spryker\Client\Search\SearchClient::writeDocument()} instead.
244
     *
245
     * @param array<string, mixed> $dataSet
246
     * @param string|null $typeName
247
     * @param string|null $indexName
248
     *
249
     * @return bool
250
     */
251
    public function write(array $dataSet, $typeName = null, $indexName = null)
252
    {
253
        return $this
254
            ->getFactory()
255
            ->createWriter()
256
            ->write($dataSet, $typeName, $indexName);
257
    }
258
259
    /**
260
     * {@inheritDoc}
261
     *
262
     * @api
263
     *
264
     * @deprecated Use {@link \Spryker\Client\Search\SearchClient::writeDocuments()} instead.
265
     *
266
     * @param array<\Generated\Shared\Transfer\SearchDocumentTransfer> $searchDocumentTransfers
267
     *
268
     * @return bool
269
     */
270
    public function writeBulk(array $searchDocumentTransfers): bool
271
    {
272
        return $this
273
            ->getFactory()
274
            ->createWriter()
275
            ->writeBulk($searchDocumentTransfers);
276
    }
277
278
    /**
279
     * {@inheritDoc}
280
     *
281
     * @api
282
     *
283
     * @deprecated Use {@link \Spryker\Client\Search\SearchClient::deleteDocument()} instead.
284
     *
285
     * @param array<string, mixed> $dataSet
286
     * @param string|null $typeName
287
     * @param string|null $indexName
288
     *
289
     * @return bool
290
     */
291
    public function delete(array $dataSet, $typeName = null, $indexName = null)
292
    {
293
        return $this
294
            ->getFactory()
295
            ->createWriter()
296
            ->delete($dataSet, $typeName, $indexName);
297
    }
298
299
    /**
300
     * {@inheritDoc}
301
     *
302
     * @api
303
     *
304
     * @deprecated Use {@link \Spryker\Client\Search\SearchClient::deleteDocuments()} instead.
305
     *
306
     * @param array<\Generated\Shared\Transfer\SearchDocumentTransfer> $searchDocumentTransfers
307
     *
308
     * @return bool
309
     */
310
    public function deleteBulk(array $searchDocumentTransfers): bool
311
    {
312
        return $this
313
            ->getFactory()
314
            ->createWriter()
315
            ->deleteBulk($searchDocumentTransfers);
316
    }
317
}
318