|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ONGR package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace ONGR\ElasticsearchDSL; |
|
13
|
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation; |
|
15
|
|
|
use ONGR\ElasticsearchDSL\Highlight\Highlight; |
|
16
|
|
|
use ONGR\ElasticsearchDSL\InnerHit\NestedInnerHit; |
|
17
|
|
|
use ONGR\ElasticsearchDSL\Query\Compound\BoolQuery; |
|
18
|
|
|
use ONGR\ElasticsearchDSL\SearchEndpoint\AbstractSearchEndpoint; |
|
19
|
|
|
use ONGR\ElasticsearchDSL\SearchEndpoint\AggregationsEndpoint; |
|
20
|
|
|
use ONGR\ElasticsearchDSL\SearchEndpoint\HighlightEndpoint; |
|
21
|
|
|
use ONGR\ElasticsearchDSL\SearchEndpoint\InnerHitsEndpoint; |
|
22
|
|
|
use ONGR\ElasticsearchDSL\SearchEndpoint\PostFilterEndpoint; |
|
23
|
|
|
use ONGR\ElasticsearchDSL\SearchEndpoint\QueryEndpoint; |
|
24
|
|
|
use ONGR\ElasticsearchDSL\SearchEndpoint\SearchEndpointFactory; |
|
25
|
|
|
use ONGR\ElasticsearchDSL\SearchEndpoint\SearchEndpointInterface; |
|
26
|
|
|
use ONGR\ElasticsearchDSL\SearchEndpoint\SortEndpoint; |
|
27
|
|
|
use ONGR\ElasticsearchDSL\Serializer\Normalizer\CustomReferencedNormalizer; |
|
28
|
|
|
use ONGR\ElasticsearchDSL\Serializer\OrderedSerializer; |
|
29
|
|
|
use Symfony\Component\Serializer\Normalizer\CustomNormalizer; |
|
30
|
|
|
use ONGR\ElasticsearchDSL\SearchEndpoint\SuggestEndpoint; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Search object that can be executed by a manager. |
|
34
|
|
|
*/ |
|
35
|
|
|
class Search |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* To retrieve hits from a certain offset. Defaults to 0. |
|
39
|
|
|
* |
|
40
|
|
|
* @var int |
|
41
|
|
|
*/ |
|
42
|
|
|
private $from; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The number of hits to return. Defaults to 10. If you do not care about getting some |
|
46
|
|
|
* hits back but only about the number of matches and/or aggregations, setting the value |
|
47
|
|
|
* to 0 will help performance. |
|
48
|
|
|
* |
|
49
|
|
|
* @var int |
|
50
|
|
|
*/ |
|
51
|
|
|
private $size; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Allows to control how the _source field is returned with every hit. By default |
|
55
|
|
|
* operations return the contents of the _source field unless you have used the |
|
56
|
|
|
* stored_fields parameter or if the _source field is disabled. |
|
57
|
|
|
* |
|
58
|
|
|
* @var bool |
|
59
|
|
|
*/ |
|
60
|
|
|
private $source; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Allows to selectively load specific stored fields for each document represented by a search hit. |
|
64
|
|
|
* |
|
65
|
|
|
* @var array |
|
66
|
|
|
*/ |
|
67
|
|
|
private $storedFields; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Allows to return a script evaluation (based on different fields) for each hit. |
|
71
|
|
|
* Script fields can work on fields that are not stored, and allow to return custom |
|
72
|
|
|
* values to be returned (the evaluated value of the script). Script fields can |
|
73
|
|
|
* also access the actual _source document indexed and extract specific elements |
|
74
|
|
|
* to be returned from it (can be an "object" type). |
|
75
|
|
|
* |
|
76
|
|
|
* @var array |
|
77
|
|
|
*/ |
|
78
|
|
|
private $scriptFields; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Allows to return the doc value representation of a field for each hit. Doc value |
|
82
|
|
|
* fields can work on fields that are not stored. Note that if the fields parameter |
|
83
|
|
|
* specifies fields without docvalues it will try to load the value from the fielddata |
|
84
|
|
|
* cache causing the terms for that field to be loaded to memory (cached), which will |
|
85
|
|
|
* result in more memory consumption. |
|
86
|
|
|
* |
|
87
|
|
|
* @var array |
|
88
|
|
|
*/ |
|
89
|
|
|
private $docValueFields; |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Enables explanation for each hit on how its score was computed. |
|
93
|
|
|
* |
|
94
|
|
|
* @var bool |
|
95
|
|
|
*/ |
|
96
|
|
|
private $explain; |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Returns a version for each search hit. |
|
100
|
|
|
* |
|
101
|
|
|
* @var bool |
|
102
|
|
|
*/ |
|
103
|
|
|
private $version; |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Allows to configure different boost level per index when searching across more |
|
107
|
|
|
* than one indices. This is very handy when hits coming from one index matter more |
|
108
|
|
|
* than hits coming from another index (think social graph where each user has an index). |
|
109
|
|
|
* |
|
110
|
|
|
* @var array |
|
111
|
|
|
*/ |
|
112
|
|
|
private $indicesBoost; |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Exclude documents which have a _score less than the minimum specified in min_score. |
|
116
|
|
|
* |
|
117
|
|
|
* @var int |
|
118
|
|
|
*/ |
|
119
|
|
|
private $minScore; |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Pagination of results can be done by using the from and size but the cost becomes |
|
123
|
|
|
* prohibitive when the deep pagination is reached. The index.max_result_window which |
|
124
|
|
|
* defaults to 10,000 is a safeguard, search requests take heap memory and time |
|
125
|
|
|
* proportional to from + size. The Scroll api is recommended for efficient deep |
|
126
|
|
|
* scrolling but scroll contexts are costly and it is not recommended to use it for |
|
127
|
|
|
* real time user requests. The search_after parameter circumvents this problem by |
|
128
|
|
|
* providing a live cursor. The idea is to use the results from the previous page to |
|
129
|
|
|
* help the retrieval of the next page. |
|
130
|
|
|
* |
|
131
|
|
|
* @var array |
|
132
|
|
|
*/ |
|
133
|
|
|
private $searchAfter; |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* URI parameters alongside Request body search. |
|
137
|
|
|
* |
|
138
|
|
|
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html |
|
139
|
|
|
* |
|
140
|
|
|
* @var array |
|
141
|
|
|
*/ |
|
142
|
|
|
private $uriParams = []; |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* While a search request returns a single “page” of results, the scroll API can be used to retrieve |
|
146
|
|
|
* large numbers of results (or even all results) from a single search request, in much the same way |
|
147
|
|
|
* as you would use a cursor on a traditional database. Scrolling is not intended for real time user |
|
148
|
|
|
* requests, but rather for processing large amounts of data, e.g. in order to reindex the contents |
|
149
|
|
|
* of one index into a new index with a different configuration. |
|
150
|
|
|
* |
|
151
|
|
|
* @var string |
|
152
|
|
|
*/ |
|
153
|
|
|
private $scroll; |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @var OrderedSerializer |
|
157
|
|
|
*/ |
|
158
|
|
|
private $serializer; |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @var SearchEndpointInterface[] |
|
162
|
|
|
*/ |
|
163
|
|
|
private $endpoints = []; |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Initializes serializer. |
|
167
|
|
|
*/ |
|
168
|
|
|
public function __construct() |
|
169
|
|
|
{ |
|
170
|
|
|
$this->serializer = new OrderedSerializer( |
|
171
|
|
|
[ |
|
172
|
|
|
new CustomReferencedNormalizer(), |
|
173
|
|
|
new CustomNormalizer(), |
|
174
|
|
|
] |
|
175
|
|
|
); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Destroys search endpoint. |
|
180
|
|
|
* |
|
181
|
|
|
* @param string $type Endpoint type. |
|
182
|
|
|
*/ |
|
183
|
|
|
public function destroyEndpoint($type) |
|
184
|
|
|
{ |
|
185
|
|
|
unset($this->endpoints[$type]); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Adds query to the search. |
|
190
|
|
|
* |
|
191
|
|
|
* @param BuilderInterface $query |
|
192
|
|
|
* @param string $boolType |
|
193
|
|
|
* @param string $key |
|
194
|
|
|
* |
|
195
|
|
|
* @return $this |
|
196
|
|
|
*/ |
|
197
|
|
|
public function addQuery(BuilderInterface $query, $boolType = BoolQuery::MUST, $key = null) |
|
198
|
|
|
{ |
|
199
|
|
|
$endpoint = $this->getEndpoint(QueryEndpoint::NAME); |
|
200
|
|
|
$endpoint->addToBool($query, $boolType, $key); |
|
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
return $this; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Adds multiple queries to the search. |
|
207
|
|
|
* |
|
208
|
|
|
* @param Array $query |
|
|
|
|
|
|
209
|
|
|
* @param string $boolType |
|
|
|
|
|
|
210
|
|
|
* @param string $key |
|
|
|
|
|
|
211
|
|
|
* |
|
212
|
|
|
* @return $this |
|
213
|
|
|
*/ |
|
214
|
|
|
public function addQueries(Array $queries) |
|
215
|
|
|
{ |
|
216
|
|
|
foreach ($queries as $query) { |
|
217
|
|
|
if (is_array($query)) { |
|
218
|
|
|
$this->addQuery(...$query); |
|
|
|
|
|
|
219
|
|
|
} else { |
|
220
|
|
|
$this->addQuery($query); |
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
return $this; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* Returns endpoint instance. |
|
229
|
|
|
* |
|
230
|
|
|
* @param string $type Endpoint type. |
|
231
|
|
|
* |
|
232
|
|
|
* @return SearchEndpointInterface |
|
233
|
|
|
*/ |
|
234
|
|
|
private function getEndpoint($type) |
|
235
|
|
|
{ |
|
236
|
|
|
if (!array_key_exists($type, $this->endpoints)) { |
|
237
|
|
|
$this->endpoints[$type] = SearchEndpointFactory::get($type); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
return $this->endpoints[$type]; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* Returns queries inside BoolQuery instance. |
|
245
|
|
|
* |
|
246
|
|
|
* @return BuilderInterface |
|
247
|
|
|
*/ |
|
248
|
|
|
public function getQueries() |
|
249
|
|
|
{ |
|
250
|
|
|
$endpoint = $this->getEndpoint(QueryEndpoint::NAME); |
|
251
|
|
|
|
|
252
|
|
|
return $endpoint->getBool(); |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* Sets query endpoint parameters. |
|
257
|
|
|
* |
|
258
|
|
|
* @param array $parameters |
|
259
|
|
|
* |
|
260
|
|
|
* @return $this |
|
261
|
|
|
*/ |
|
262
|
|
|
public function setQueryParameters(array $parameters) |
|
263
|
|
|
{ |
|
264
|
|
|
$this->setEndpointParameters(QueryEndpoint::NAME, $parameters); |
|
265
|
|
|
|
|
266
|
|
|
return $this; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Sets parameters to the endpoint. |
|
271
|
|
|
* |
|
272
|
|
|
* @param string $endpointName |
|
273
|
|
|
* @param array $parameters |
|
274
|
|
|
*/ |
|
275
|
|
|
public function setEndpointParameters($endpointName, array $parameters) |
|
276
|
|
|
{ |
|
277
|
|
|
/** @var AbstractSearchEndpoint $endpoint */ |
|
278
|
|
|
$endpoint = $this->getEndpoint($endpointName); |
|
279
|
|
|
$endpoint->setParameters($parameters); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* Adds a post filter to search. |
|
284
|
|
|
* |
|
285
|
|
|
* @param BuilderInterface $filter Filter. |
|
286
|
|
|
* @param string $boolType Example boolType values: |
|
287
|
|
|
* - must |
|
288
|
|
|
* - must_not |
|
289
|
|
|
* - should. |
|
290
|
|
|
* @param string $key |
|
291
|
|
|
* |
|
292
|
|
|
* @return $this. |
|
|
|
|
|
|
293
|
|
|
*/ |
|
294
|
|
|
public function addPostFilter(BuilderInterface $filter, $boolType = BoolQuery::MUST, $key = null) |
|
295
|
|
|
{ |
|
296
|
|
|
$this |
|
297
|
|
|
->getEndpoint(PostFilterEndpoint::NAME) |
|
298
|
|
|
->addToBool($filter, $boolType, $key); |
|
|
|
|
|
|
299
|
|
|
|
|
300
|
|
|
return $this; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* Returns queries inside BoolFilter instance. |
|
305
|
|
|
* |
|
306
|
|
|
* @return BuilderInterface |
|
307
|
|
|
*/ |
|
308
|
|
|
public function getPostFilters() |
|
309
|
|
|
{ |
|
310
|
|
|
$endpoint = $this->getEndpoint(PostFilterEndpoint::NAME); |
|
311
|
|
|
|
|
312
|
|
|
return $endpoint->getBool(); |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* Sets post filter endpoint parameters. |
|
317
|
|
|
* |
|
318
|
|
|
* @param array $parameters |
|
319
|
|
|
* |
|
320
|
|
|
* @return $this |
|
321
|
|
|
*/ |
|
322
|
|
|
public function setPostFilterParameters(array $parameters) |
|
323
|
|
|
{ |
|
324
|
|
|
$this->setEndpointParameters(PostFilterEndpoint::NAME, $parameters); |
|
325
|
|
|
|
|
326
|
|
|
return $this; |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* Adds aggregation into search. |
|
331
|
|
|
* |
|
332
|
|
|
* @param AbstractAggregation $aggregation |
|
333
|
|
|
* |
|
334
|
|
|
* @return $this |
|
335
|
|
|
*/ |
|
336
|
|
|
public function addAggregation(AbstractAggregation $aggregation) |
|
337
|
|
|
{ |
|
338
|
|
|
$this->getEndpoint(AggregationsEndpoint::NAME)->add($aggregation, $aggregation->getName()); |
|
339
|
|
|
|
|
340
|
|
|
return $this; |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
/** |
|
344
|
|
|
* Returns all aggregations. |
|
345
|
|
|
* |
|
346
|
|
|
* @return BuilderInterface[] |
|
347
|
|
|
*/ |
|
348
|
|
|
public function getAggregations() |
|
349
|
|
|
{ |
|
350
|
|
|
return $this->getEndpoint(AggregationsEndpoint::NAME)->getAll(); |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
/** |
|
354
|
|
|
* Adds inner hit into search. |
|
355
|
|
|
* |
|
356
|
|
|
* @param NestedInnerHit $innerHit |
|
357
|
|
|
* |
|
358
|
|
|
* @return $this |
|
359
|
|
|
*/ |
|
360
|
|
|
public function addInnerHit(NestedInnerHit $innerHit) |
|
361
|
|
|
{ |
|
362
|
|
|
$this->getEndpoint(InnerHitsEndpoint::NAME)->add($innerHit, $innerHit->getName()); |
|
363
|
|
|
|
|
364
|
|
|
return $this; |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
/** |
|
368
|
|
|
* Returns all inner hits. |
|
369
|
|
|
* |
|
370
|
|
|
* @return BuilderInterface[] |
|
371
|
|
|
*/ |
|
372
|
|
|
public function getInnerHits() |
|
373
|
|
|
{ |
|
374
|
|
|
return $this->getEndpoint(InnerHitsEndpoint::NAME)->getAll(); |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* Adds sort to search. |
|
379
|
|
|
* |
|
380
|
|
|
* @param BuilderInterface $sort |
|
381
|
|
|
* |
|
382
|
|
|
* @return $this |
|
383
|
|
|
*/ |
|
384
|
|
|
public function addSort(BuilderInterface $sort) |
|
385
|
|
|
{ |
|
386
|
|
|
$this->getEndpoint(SortEndpoint::NAME)->add($sort); |
|
387
|
|
|
|
|
388
|
|
|
return $this; |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
/** |
|
392
|
|
|
* Returns all set sorts. |
|
393
|
|
|
* |
|
394
|
|
|
* @return BuilderInterface[] |
|
395
|
|
|
*/ |
|
396
|
|
|
public function getSorts() |
|
397
|
|
|
{ |
|
398
|
|
|
return $this->getEndpoint(SortEndpoint::NAME)->getAll(); |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
/** |
|
402
|
|
|
* Allows to highlight search results on one or more fields. |
|
403
|
|
|
* |
|
404
|
|
|
* @param Highlight $highlight |
|
405
|
|
|
* |
|
406
|
|
|
* @return $this. |
|
|
|
|
|
|
407
|
|
|
*/ |
|
408
|
|
|
public function addHighlight($highlight) |
|
409
|
|
|
{ |
|
410
|
|
|
$this->getEndpoint(HighlightEndpoint::NAME)->add($highlight); |
|
411
|
|
|
|
|
412
|
|
|
return $this; |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
/** |
|
416
|
|
|
* Returns highlight builder. |
|
417
|
|
|
* |
|
418
|
|
|
* @return BuilderInterface |
|
419
|
|
|
*/ |
|
420
|
|
|
public function getHighlights() |
|
421
|
|
|
{ |
|
422
|
|
|
/** @var HighlightEndpoint $highlightEndpoint */ |
|
423
|
|
|
$highlightEndpoint = $this->getEndpoint(HighlightEndpoint::NAME); |
|
424
|
|
|
|
|
425
|
|
|
return $highlightEndpoint->getHighlight(); |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
/** |
|
429
|
|
|
* Adds suggest into search. |
|
430
|
|
|
* |
|
431
|
|
|
* @param BuilderInterface $suggest |
|
432
|
|
|
* |
|
433
|
|
|
* @return $this |
|
434
|
|
|
*/ |
|
435
|
|
|
public function addSuggest(BuilderInterface $suggest) |
|
436
|
|
|
{ |
|
437
|
|
|
$this->getEndpoint(SuggestEndpoint::NAME)->add($suggest, $suggest->getName()); |
|
|
|
|
|
|
438
|
|
|
|
|
439
|
|
|
return $this; |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
/** |
|
443
|
|
|
* Returns all suggests. |
|
444
|
|
|
* |
|
445
|
|
|
* @return BuilderInterface[] |
|
446
|
|
|
*/ |
|
447
|
|
|
public function getSuggests() |
|
448
|
|
|
{ |
|
449
|
|
|
return $this->getEndpoint(SuggestEndpoint::NAME)->getAll(); |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
/** |
|
453
|
|
|
* @return int |
|
454
|
|
|
*/ |
|
455
|
|
|
public function getFrom() |
|
456
|
|
|
{ |
|
457
|
|
|
return $this->from; |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
|
|
/** |
|
461
|
|
|
* @param int $from |
|
462
|
|
|
* @return $this |
|
463
|
|
|
*/ |
|
464
|
|
|
public function setFrom($from) |
|
465
|
|
|
{ |
|
466
|
|
|
$this->from = $from; |
|
467
|
|
|
return $this; |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
/** |
|
471
|
|
|
* @return int |
|
472
|
|
|
*/ |
|
473
|
|
|
public function getSize() |
|
474
|
|
|
{ |
|
475
|
|
|
return $this->size; |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
/** |
|
479
|
|
|
* @param int $size |
|
480
|
|
|
* @return $this |
|
481
|
|
|
*/ |
|
482
|
|
|
public function setSize($size) |
|
483
|
|
|
{ |
|
484
|
|
|
$this->size = $size; |
|
485
|
|
|
return $this; |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
/** |
|
489
|
|
|
* @return bool |
|
490
|
|
|
*/ |
|
491
|
|
|
public function isSource() |
|
492
|
|
|
{ |
|
493
|
|
|
return $this->source; |
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
/** |
|
497
|
|
|
* @param bool $source |
|
498
|
|
|
* @return $this |
|
499
|
|
|
*/ |
|
500
|
|
|
public function setSource($source) |
|
501
|
|
|
{ |
|
502
|
|
|
$this->source = $source; |
|
503
|
|
|
return $this; |
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
|
/** |
|
507
|
|
|
* @return array |
|
508
|
|
|
*/ |
|
509
|
|
|
public function getStoredFields() |
|
510
|
|
|
{ |
|
511
|
|
|
return $this->storedFields; |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
/** |
|
515
|
|
|
* @param array $storedFields |
|
516
|
|
|
* @return $this |
|
517
|
|
|
*/ |
|
518
|
|
|
public function setStoredFields($storedFields) |
|
519
|
|
|
{ |
|
520
|
|
|
$this->storedFields = $storedFields; |
|
521
|
|
|
return $this; |
|
522
|
|
|
} |
|
523
|
|
|
|
|
524
|
|
|
/** |
|
525
|
|
|
* @return array |
|
526
|
|
|
*/ |
|
527
|
|
|
public function getScriptFields() |
|
528
|
|
|
{ |
|
529
|
|
|
return $this->scriptFields; |
|
530
|
|
|
} |
|
531
|
|
|
|
|
532
|
|
|
/** |
|
533
|
|
|
* @param array $scriptFields |
|
534
|
|
|
* @return $this |
|
535
|
|
|
*/ |
|
536
|
|
|
public function setScriptFields($scriptFields) |
|
537
|
|
|
{ |
|
538
|
|
|
$this->scriptFields = $scriptFields; |
|
539
|
|
|
return $this; |
|
540
|
|
|
} |
|
541
|
|
|
|
|
542
|
|
|
/** |
|
543
|
|
|
* @return array |
|
544
|
|
|
*/ |
|
545
|
|
|
public function getDocValueFields() |
|
546
|
|
|
{ |
|
547
|
|
|
return $this->docValueFields; |
|
548
|
|
|
} |
|
549
|
|
|
|
|
550
|
|
|
/** |
|
551
|
|
|
* @param array $docValueFields |
|
552
|
|
|
* @return $this |
|
553
|
|
|
*/ |
|
554
|
|
|
public function setDocValueFields($docValueFields) |
|
555
|
|
|
{ |
|
556
|
|
|
$this->docValueFields = $docValueFields; |
|
557
|
|
|
return $this; |
|
558
|
|
|
} |
|
559
|
|
|
|
|
560
|
|
|
/** |
|
561
|
|
|
* @return bool |
|
562
|
|
|
*/ |
|
563
|
|
|
public function isExplain() |
|
564
|
|
|
{ |
|
565
|
|
|
return $this->explain; |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
/** |
|
569
|
|
|
* @param bool $explain |
|
570
|
|
|
* @return $this |
|
571
|
|
|
*/ |
|
572
|
|
|
public function setExplain($explain) |
|
573
|
|
|
{ |
|
574
|
|
|
$this->explain = $explain; |
|
575
|
|
|
return $this; |
|
576
|
|
|
} |
|
577
|
|
|
|
|
578
|
|
|
/** |
|
579
|
|
|
* @return bool |
|
580
|
|
|
*/ |
|
581
|
|
|
public function isVersion() |
|
582
|
|
|
{ |
|
583
|
|
|
return $this->version; |
|
584
|
|
|
} |
|
585
|
|
|
|
|
586
|
|
|
/** |
|
587
|
|
|
* @param bool $version |
|
588
|
|
|
* @return $this |
|
589
|
|
|
*/ |
|
590
|
|
|
public function setVersion($version) |
|
591
|
|
|
{ |
|
592
|
|
|
$this->version = $version; |
|
593
|
|
|
return $this; |
|
594
|
|
|
} |
|
595
|
|
|
|
|
596
|
|
|
/** |
|
597
|
|
|
* @return array |
|
598
|
|
|
*/ |
|
599
|
|
|
public function getIndicesBoost() |
|
600
|
|
|
{ |
|
601
|
|
|
return $this->indicesBoost; |
|
602
|
|
|
} |
|
603
|
|
|
|
|
604
|
|
|
/** |
|
605
|
|
|
* @param array $indicesBoost |
|
606
|
|
|
* @return $this |
|
607
|
|
|
*/ |
|
608
|
|
|
public function setIndicesBoost($indicesBoost) |
|
609
|
|
|
{ |
|
610
|
|
|
$this->indicesBoost = $indicesBoost; |
|
611
|
|
|
return $this; |
|
612
|
|
|
} |
|
613
|
|
|
|
|
614
|
|
|
/** |
|
615
|
|
|
* @return int |
|
616
|
|
|
*/ |
|
617
|
|
|
public function getMinScore() |
|
618
|
|
|
{ |
|
619
|
|
|
return $this->minScore; |
|
620
|
|
|
} |
|
621
|
|
|
|
|
622
|
|
|
/** |
|
623
|
|
|
* @param int $minScore |
|
624
|
|
|
* @return $this |
|
625
|
|
|
*/ |
|
626
|
|
|
public function setMinScore($minScore) |
|
627
|
|
|
{ |
|
628
|
|
|
$this->minScore = $minScore; |
|
629
|
|
|
return $this; |
|
630
|
|
|
} |
|
631
|
|
|
|
|
632
|
|
|
/** |
|
633
|
|
|
* @return array |
|
634
|
|
|
*/ |
|
635
|
|
|
public function getSearchAfter() |
|
636
|
|
|
{ |
|
637
|
|
|
return $this->searchAfter; |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
/** |
|
641
|
|
|
* @param array $searchAfter |
|
642
|
|
|
* @return $this |
|
643
|
|
|
*/ |
|
644
|
|
|
public function setSearchAfter($searchAfter) |
|
645
|
|
|
{ |
|
646
|
|
|
$this->searchAfter = $searchAfter; |
|
647
|
|
|
return $this; |
|
648
|
|
|
} |
|
649
|
|
|
|
|
650
|
|
|
/** |
|
651
|
|
|
* @return string |
|
652
|
|
|
*/ |
|
653
|
|
|
public function getScroll() |
|
654
|
|
|
{ |
|
655
|
|
|
return $this->scroll; |
|
656
|
|
|
} |
|
657
|
|
|
|
|
658
|
|
|
/** |
|
659
|
|
|
* @param string $scroll |
|
660
|
|
|
* @return $this |
|
661
|
|
|
*/ |
|
662
|
|
|
public function setScroll($scroll = '5m') |
|
663
|
|
|
{ |
|
664
|
|
|
$this->scroll = $scroll; |
|
665
|
|
|
|
|
666
|
|
|
$this->addUriParam('scroll', $this->scroll); |
|
667
|
|
|
|
|
668
|
|
|
return $this; |
|
669
|
|
|
} |
|
670
|
|
|
|
|
671
|
|
|
/** |
|
672
|
|
|
* @param string $name |
|
673
|
|
|
* @param string|array|bool $value |
|
674
|
|
|
* |
|
675
|
|
|
* @return $this |
|
676
|
|
|
*/ |
|
677
|
|
|
public function addUriParam($name, $value) |
|
678
|
|
|
{ |
|
679
|
|
|
if (in_array($name, [ |
|
680
|
|
|
'q', |
|
681
|
|
|
'df', |
|
682
|
|
|
'analyzer', |
|
683
|
|
|
'analyze_wildcard', |
|
684
|
|
|
'default_operator', |
|
685
|
|
|
'lenient', |
|
686
|
|
|
'explain', |
|
687
|
|
|
'_source', |
|
688
|
|
|
'stored_fields', |
|
689
|
|
|
'sort', |
|
690
|
|
|
'track_scores', |
|
691
|
|
|
'timeout', |
|
692
|
|
|
'terminate_after', |
|
693
|
|
|
'from', |
|
694
|
|
|
'size', |
|
695
|
|
|
'search_type', |
|
696
|
|
|
'scroll', |
|
697
|
|
|
])) { |
|
698
|
|
|
$this->uriParams[$name] = $value; |
|
699
|
|
|
} else { |
|
700
|
|
|
throw new \InvalidArgumentException(sprintf('Parameter %s is not supported.', $value)); |
|
701
|
|
|
} |
|
702
|
|
|
|
|
703
|
|
|
return $this; |
|
704
|
|
|
} |
|
705
|
|
|
|
|
706
|
|
|
/** |
|
707
|
|
|
* Returns query url parameters. |
|
708
|
|
|
* |
|
709
|
|
|
* @return array |
|
710
|
|
|
*/ |
|
711
|
|
|
public function getUriParams() |
|
712
|
|
|
{ |
|
713
|
|
|
return $this->uriParams; |
|
714
|
|
|
} |
|
715
|
|
|
|
|
716
|
|
|
/** |
|
717
|
|
|
* {@inheritdoc} |
|
718
|
|
|
*/ |
|
719
|
|
|
public function toArray() |
|
720
|
|
|
{ |
|
721
|
|
|
$output = array_filter($this->serializer->normalize($this->endpoints)); |
|
|
|
|
|
|
722
|
|
|
|
|
723
|
|
|
$params = [ |
|
724
|
|
|
'from' => 'from', |
|
725
|
|
|
'size' => 'size', |
|
726
|
|
|
'source' => '_source', |
|
727
|
|
|
'storedFields' => 'stored_fields', |
|
728
|
|
|
'scriptFields' => 'script_fields', |
|
729
|
|
|
'docValueFields' => 'docvalue_fields', |
|
730
|
|
|
'explain' => 'explain', |
|
731
|
|
|
'version' => 'version', |
|
732
|
|
|
'indicesBoost' => 'indices_boost', |
|
733
|
|
|
'minScore' => 'min_score', |
|
734
|
|
|
'searchAfter' => 'search_after', |
|
735
|
|
|
]; |
|
736
|
|
|
|
|
737
|
|
|
foreach ($params as $field => $param) { |
|
738
|
|
|
if ($this->$field !== null) { |
|
739
|
|
|
$output[$param] = $this->$field; |
|
740
|
|
|
} |
|
741
|
|
|
} |
|
742
|
|
|
|
|
743
|
|
|
return $output; |
|
744
|
|
|
} |
|
745
|
|
|
} |
|
746
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: