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
|
|
|
* Returns endpoint instance. |
207
|
|
|
* |
208
|
|
|
* @param string $type Endpoint type. |
209
|
|
|
* |
210
|
|
|
* @return SearchEndpointInterface |
211
|
|
|
*/ |
212
|
|
|
private function getEndpoint($type) |
213
|
|
|
{ |
214
|
|
|
if (!array_key_exists($type, $this->endpoints)) { |
215
|
|
|
$this->endpoints[$type] = SearchEndpointFactory::get($type); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
return $this->endpoints[$type]; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Returns queries inside BoolQuery instance. |
223
|
|
|
* |
224
|
|
|
* @return BuilderInterface |
225
|
|
|
*/ |
226
|
|
|
public function getQueries() |
227
|
|
|
{ |
228
|
|
|
$endpoint = $this->getEndpoint(QueryEndpoint::NAME); |
229
|
|
|
|
230
|
|
|
return $endpoint->getBool(); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Sets query endpoint parameters. |
235
|
|
|
* |
236
|
|
|
* @param array $parameters |
237
|
|
|
* |
238
|
|
|
* @return $this |
239
|
|
|
*/ |
240
|
|
|
public function setQueryParameters(array $parameters) |
241
|
|
|
{ |
242
|
|
|
$this->setEndpointParameters(QueryEndpoint::NAME, $parameters); |
243
|
|
|
|
244
|
|
|
return $this; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Sets parameters to the endpoint. |
249
|
|
|
* |
250
|
|
|
* @param string $endpointName |
251
|
|
|
* @param array $parameters |
252
|
|
|
*/ |
253
|
|
|
public function setEndpointParameters($endpointName, array $parameters) |
254
|
|
|
{ |
255
|
|
|
/** @var AbstractSearchEndpoint $endpoint */ |
256
|
|
|
$endpoint = $this->getEndpoint($endpointName); |
257
|
|
|
$endpoint->setParameters($parameters); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Adds a post filter to search. |
262
|
|
|
* |
263
|
|
|
* @param BuilderInterface $filter Filter. |
264
|
|
|
* @param string $boolType Example boolType values: |
265
|
|
|
* - must |
266
|
|
|
* - must_not |
267
|
|
|
* - should. |
268
|
|
|
* @param string $key |
269
|
|
|
* |
270
|
|
|
* @return $this. |
|
|
|
|
271
|
|
|
*/ |
272
|
|
|
public function addPostFilter(BuilderInterface $filter, $boolType = BoolQuery::MUST, $key = null) |
273
|
|
|
{ |
274
|
|
|
$this |
275
|
|
|
->getEndpoint(PostFilterEndpoint::NAME) |
276
|
|
|
->addToBool($filter, $boolType, $key); |
|
|
|
|
277
|
|
|
|
278
|
|
|
return $this; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Returns queries inside BoolFilter instance. |
283
|
|
|
* |
284
|
|
|
* @return BuilderInterface |
285
|
|
|
*/ |
286
|
|
|
public function getPostFilters() |
287
|
|
|
{ |
288
|
|
|
$endpoint = $this->getEndpoint(PostFilterEndpoint::NAME); |
289
|
|
|
|
290
|
|
|
return $endpoint->getBool(); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Sets post filter endpoint parameters. |
295
|
|
|
* |
296
|
|
|
* @param array $parameters |
297
|
|
|
* |
298
|
|
|
* @return $this |
299
|
|
|
*/ |
300
|
|
|
public function setPostFilterParameters(array $parameters) |
301
|
|
|
{ |
302
|
|
|
$this->setEndpointParameters(PostFilterEndpoint::NAME, $parameters); |
303
|
|
|
|
304
|
|
|
return $this; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Adds aggregation into search. |
309
|
|
|
* |
310
|
|
|
* @param AbstractAggregation $aggregation |
311
|
|
|
* |
312
|
|
|
* @return $this |
313
|
|
|
*/ |
314
|
|
|
public function addAggregation(AbstractAggregation $aggregation) |
315
|
|
|
{ |
316
|
|
|
$this->getEndpoint(AggregationsEndpoint::NAME)->add($aggregation, $aggregation->getName()); |
317
|
|
|
|
318
|
|
|
return $this; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Returns all aggregations. |
323
|
|
|
* |
324
|
|
|
* @return BuilderInterface[] |
325
|
|
|
*/ |
326
|
|
|
public function getAggregations() |
327
|
|
|
{ |
328
|
|
|
return $this->getEndpoint(AggregationsEndpoint::NAME)->getAll(); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Adds inner hit into search. |
333
|
|
|
* |
334
|
|
|
* @param NestedInnerHit $innerHit |
335
|
|
|
* |
336
|
|
|
* @return $this |
337
|
|
|
*/ |
338
|
|
|
public function addInnerHit(NestedInnerHit $innerHit) |
339
|
|
|
{ |
340
|
|
|
$this->getEndpoint(InnerHitsEndpoint::NAME)->add($innerHit, $innerHit->getName()); |
341
|
|
|
|
342
|
|
|
return $this; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Returns all inner hits. |
347
|
|
|
* |
348
|
|
|
* @return BuilderInterface[] |
349
|
|
|
*/ |
350
|
|
|
public function getInnerHits() |
351
|
|
|
{ |
352
|
|
|
return $this->getEndpoint(InnerHitsEndpoint::NAME)->getAll(); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* Adds sort to search. |
357
|
|
|
* |
358
|
|
|
* @param BuilderInterface $sort |
359
|
|
|
* |
360
|
|
|
* @return $this |
361
|
|
|
*/ |
362
|
|
|
public function addSort(BuilderInterface $sort) |
363
|
|
|
{ |
364
|
|
|
$this->getEndpoint(SortEndpoint::NAME)->add($sort); |
365
|
|
|
|
366
|
|
|
return $this; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Returns all set sorts. |
371
|
|
|
* |
372
|
|
|
* @return BuilderInterface[] |
373
|
|
|
*/ |
374
|
|
|
public function getSorts() |
375
|
|
|
{ |
376
|
|
|
return $this->getEndpoint(SortEndpoint::NAME)->getAll(); |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* Allows to highlight search results on one or more fields. |
381
|
|
|
* |
382
|
|
|
* @param Highlight $highlight |
383
|
|
|
* |
384
|
|
|
* @return $this. |
|
|
|
|
385
|
|
|
*/ |
386
|
|
|
public function addHighlight($highlight) |
387
|
|
|
{ |
388
|
|
|
$this->getEndpoint(HighlightEndpoint::NAME)->add($highlight); |
389
|
|
|
|
390
|
|
|
return $this; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Returns highlight builder. |
395
|
|
|
* |
396
|
|
|
* @return BuilderInterface |
397
|
|
|
*/ |
398
|
|
|
public function getHighlights() |
399
|
|
|
{ |
400
|
|
|
/** @var HighlightEndpoint $highlightEndpoint */ |
401
|
|
|
$highlightEndpoint = $this->getEndpoint(HighlightEndpoint::NAME); |
402
|
|
|
|
403
|
|
|
return $highlightEndpoint->getHighlight(); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* Adds suggest into search. |
408
|
|
|
* |
409
|
|
|
* @param BuilderInterface $suggest |
410
|
|
|
* |
411
|
|
|
* @return $this |
412
|
|
|
*/ |
413
|
|
|
public function addSuggest(BuilderInterface $suggest) |
414
|
|
|
{ |
415
|
|
|
$this->getEndpoint(SuggestEndpoint::NAME)->add($suggest, $suggest->getName()); |
|
|
|
|
416
|
|
|
|
417
|
|
|
return $this; |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* Returns all suggests. |
422
|
|
|
* |
423
|
|
|
* @return BuilderInterface[] |
424
|
|
|
*/ |
425
|
|
|
public function getSuggests() |
426
|
|
|
{ |
427
|
|
|
return $this->getEndpoint(SuggestEndpoint::NAME)->getAll(); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* @return int |
432
|
|
|
*/ |
433
|
|
|
public function getFrom() |
434
|
|
|
{ |
435
|
|
|
return $this->from; |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* @param int $from |
440
|
|
|
* @return $this |
441
|
|
|
*/ |
442
|
|
|
public function setFrom($from) |
443
|
|
|
{ |
444
|
|
|
$this->from = $from; |
445
|
|
|
return $this; |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* @return int |
450
|
|
|
*/ |
451
|
|
|
public function getSize() |
452
|
|
|
{ |
453
|
|
|
return $this->size; |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
/** |
457
|
|
|
* @param int $size |
458
|
|
|
* @return $this |
459
|
|
|
*/ |
460
|
|
|
public function setSize($size) |
461
|
|
|
{ |
462
|
|
|
$this->size = $size; |
463
|
|
|
return $this; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* @return bool |
468
|
|
|
*/ |
469
|
|
|
public function isSource() |
470
|
|
|
{ |
471
|
|
|
return $this->source; |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
/** |
475
|
|
|
* @param bool $source |
476
|
|
|
* @return $this |
477
|
|
|
*/ |
478
|
|
|
public function setSource($source) |
479
|
|
|
{ |
480
|
|
|
$this->source = $source; |
481
|
|
|
return $this; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* @return array |
486
|
|
|
*/ |
487
|
|
|
public function getStoredFields() |
488
|
|
|
{ |
489
|
|
|
return $this->storedFields; |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* @param array $storedFields |
494
|
|
|
* @return $this |
495
|
|
|
*/ |
496
|
|
|
public function setStoredFields($storedFields) |
497
|
|
|
{ |
498
|
|
|
$this->storedFields = $storedFields; |
499
|
|
|
return $this; |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
/** |
503
|
|
|
* @return array |
504
|
|
|
*/ |
505
|
|
|
public function getScriptFields() |
506
|
|
|
{ |
507
|
|
|
return $this->scriptFields; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* @param array $scriptFields |
512
|
|
|
* @return $this |
513
|
|
|
*/ |
514
|
|
|
public function setScriptFields($scriptFields) |
515
|
|
|
{ |
516
|
|
|
$this->scriptFields = $scriptFields; |
517
|
|
|
return $this; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* @return array |
522
|
|
|
*/ |
523
|
|
|
public function getDocValueFields() |
524
|
|
|
{ |
525
|
|
|
return $this->docValueFields; |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* @param array $docValueFields |
530
|
|
|
* @return $this |
531
|
|
|
*/ |
532
|
|
|
public function setDocValueFields($docValueFields) |
533
|
|
|
{ |
534
|
|
|
$this->docValueFields = $docValueFields; |
535
|
|
|
return $this; |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
/** |
539
|
|
|
* @return bool |
540
|
|
|
*/ |
541
|
|
|
public function isExplain() |
542
|
|
|
{ |
543
|
|
|
return $this->explain; |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
/** |
547
|
|
|
* @param bool $explain |
548
|
|
|
* @return $this |
549
|
|
|
*/ |
550
|
|
|
public function setExplain($explain) |
551
|
|
|
{ |
552
|
|
|
$this->explain = $explain; |
553
|
|
|
return $this; |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
/** |
557
|
|
|
* @return bool |
558
|
|
|
*/ |
559
|
|
|
public function isVersion() |
560
|
|
|
{ |
561
|
|
|
return $this->version; |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
/** |
565
|
|
|
* @param bool $version |
566
|
|
|
* @return $this |
567
|
|
|
*/ |
568
|
|
|
public function setVersion($version) |
569
|
|
|
{ |
570
|
|
|
$this->version = $version; |
571
|
|
|
return $this; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
/** |
575
|
|
|
* @return array |
576
|
|
|
*/ |
577
|
|
|
public function getIndicesBoost() |
578
|
|
|
{ |
579
|
|
|
return $this->indicesBoost; |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
/** |
583
|
|
|
* @param array $indicesBoost |
584
|
|
|
* @return $this |
585
|
|
|
*/ |
586
|
|
|
public function setIndicesBoost($indicesBoost) |
587
|
|
|
{ |
588
|
|
|
$this->indicesBoost = $indicesBoost; |
589
|
|
|
return $this; |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* @return int |
594
|
|
|
*/ |
595
|
|
|
public function getMinScore() |
596
|
|
|
{ |
597
|
|
|
return $this->minScore; |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
/** |
601
|
|
|
* @param int $minScore |
602
|
|
|
* @return $this |
603
|
|
|
*/ |
604
|
|
|
public function setMinScore($minScore) |
605
|
|
|
{ |
606
|
|
|
$this->minScore = $minScore; |
607
|
|
|
return $this; |
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
/** |
611
|
|
|
* @return array |
612
|
|
|
*/ |
613
|
|
|
public function getSearchAfter() |
614
|
|
|
{ |
615
|
|
|
return $this->searchAfter; |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
/** |
619
|
|
|
* @param array $searchAfter |
620
|
|
|
* @return $this |
621
|
|
|
*/ |
622
|
|
|
public function setSearchAfter($searchAfter) |
623
|
|
|
{ |
624
|
|
|
$this->searchAfter = $searchAfter; |
625
|
|
|
return $this; |
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
/** |
629
|
|
|
* @return string |
630
|
|
|
*/ |
631
|
|
|
public function getScroll() |
632
|
|
|
{ |
633
|
|
|
return $this->scroll; |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
/** |
637
|
|
|
* @param string $scroll |
638
|
|
|
* @return $this |
639
|
|
|
*/ |
640
|
|
|
public function setScroll($scroll = '5m') |
641
|
|
|
{ |
642
|
|
|
$this->scroll = $scroll; |
643
|
|
|
return $this; |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
/** |
647
|
|
|
* @param string $name |
648
|
|
|
* @param string|array|bool $value |
649
|
|
|
* |
650
|
|
|
* @return $this |
651
|
|
|
*/ |
652
|
|
|
public function addUriParam($name, $value) |
653
|
|
|
{ |
654
|
|
|
if (in_array($name, [ |
655
|
|
|
'q', |
656
|
|
|
'df', |
657
|
|
|
'analyzer', |
658
|
|
|
'analyze_wildcard', |
659
|
|
|
'default_operator', |
660
|
|
|
'lenient', |
661
|
|
|
'explain', |
662
|
|
|
'_source', |
663
|
|
|
'stored_fields', |
664
|
|
|
'sort', |
665
|
|
|
'track_scores', |
666
|
|
|
'timeout', |
667
|
|
|
'terminate_after', |
668
|
|
|
'from', |
669
|
|
|
'size', |
670
|
|
|
'search_type', |
671
|
|
|
])) { |
672
|
|
|
$this->uriParams[$name] = $value; |
673
|
|
|
} else { |
674
|
|
|
throw new \InvalidArgumentException(sprintf('Parameter %s is not supported.', $value)); |
675
|
|
|
} |
676
|
|
|
|
677
|
|
|
return $this; |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
/** |
681
|
|
|
* Returns query url parameters. |
682
|
|
|
* |
683
|
|
|
* @return array |
684
|
|
|
*/ |
685
|
|
|
public function getUriParams() |
686
|
|
|
{ |
687
|
|
|
return $this->uriParams; |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
/** |
691
|
|
|
* {@inheritdoc} |
692
|
|
|
*/ |
693
|
|
|
public function toArray() |
694
|
|
|
{ |
695
|
|
|
$output = array_filter($this->serializer->normalize($this->endpoints)); |
|
|
|
|
696
|
|
|
|
697
|
|
|
$params = [ |
698
|
|
|
'from' => 'from', |
699
|
|
|
'size' => 'size', |
700
|
|
|
'source' => '_source', |
701
|
|
|
'storedFields' => 'stored_fields', |
702
|
|
|
'scriptFields' => 'script_fields', |
703
|
|
|
'docValueFields' => 'docvalue_fields', |
704
|
|
|
'explain' => 'explain', |
705
|
|
|
'version' => 'version', |
706
|
|
|
'indicesBoost' => 'indices_boost', |
707
|
|
|
'minScore' => 'min_score', |
708
|
|
|
'searchAfter' => 'search_after', |
709
|
|
|
]; |
710
|
|
|
|
711
|
|
|
foreach ($params as $field => $param) { |
712
|
|
|
if ($this->$field !== null) { |
713
|
|
|
$output[$param] = $this->$field; |
714
|
|
|
} |
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
return $output; |
718
|
|
|
} |
719
|
|
|
} |
720
|
|
|
|
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: