Completed
Pull Request — master (#288)
by
unknown
03:11
created

Search::getEndpoint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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
     * If you don’t need to track the total number of hits at all you can improve
39
     * query times by setting this option to false. Defaults to true.
40
     *
41
     * @var bool
42
     */
43
    private $trackTotalHits;
44
45
    /**
46
     * To retrieve hits from a certain offset. Defaults to 0.
47
     *
48
     * @var int
49
     */
50
    private $from;
51
52
    /**
53
     * The number of hits to return. Defaults to 10. If you do not care about getting some
54
     * hits back but only about the number of matches and/or aggregations, setting the value
55
     * to 0 will help performance.
56
     *
57
     * @var int
58
     */
59
    private $size;
60
61
    /**
62
     * Allows to control how the _source field is returned with every hit. By default
63
     * operations return the contents of the _source field unless you have used the
64
     * stored_fields parameter or if the _source field is disabled.
65
     *
66
     * @var bool
67
     */
68
    private $source;
69
70
    /**
71
     * Allows to selectively load specific stored fields for each document represented by a search hit.
72
     *
73
     * @var array
74
     */
75
    private $storedFields;
76
77
    /**
78
     * Allows to return a script evaluation (based on different fields) for each hit.
79
     * Script fields can work on fields that are not stored, and allow to return custom
80
     * values to be returned (the evaluated value of the script). Script fields can
81
     * also access the actual _source document indexed and extract specific elements
82
     * to be returned from it (can be an "object" type).
83
     *
84
     * @var array
85
     */
86
    private $scriptFields;
87
88
    /**
89
     * Allows to return the doc value representation of a field for each hit. Doc value
90
     * fields can work on fields that are not stored. Note that if the fields parameter
91
     * specifies fields without docvalues it will try to load the value from the fielddata
92
     * cache causing the terms for that field to be loaded to memory (cached), which will
93
     * result in more memory consumption.
94
     *
95
     * @var array
96
     */
97
    private $docValueFields;
98
99
    /**
100
     * Enables explanation for each hit on how its score was computed.
101
     *
102
     * @var bool
103
     */
104
    private $explain;
105
106
    /**
107
     * Returns a version for each search hit.
108
     *
109
     * @var bool
110
     */
111
    private $version;
112
113
    /**
114
     * Allows to configure different boost level per index when searching across more
115
     * than one indices. This is very handy when hits coming from one index matter more
116
     * than hits coming from another index (think social graph where each user has an index).
117
     *
118
     * @var array
119
     */
120
    private $indicesBoost;
121
122
    /**
123
     * Exclude documents which have a _score less than the minimum specified in min_score.
124
     *
125
     * @var int
126
     */
127
    private $minScore;
128
129
    /**
130
     * Pagination of results can be done by using the from and size but the cost becomes
131
     * prohibitive when the deep pagination is reached. The index.max_result_window which
132
     * defaults to 10,000 is a safeguard, search requests take heap memory and time
133
     * proportional to from + size. The Scroll api is recommended for efficient deep
134
     * scrolling but scroll contexts are costly and it is not recommended to use it for
135
     * real time user requests. The search_after parameter circumvents this problem by
136
     * providing a live cursor. The idea is to use the results from the previous page to
137
     * help the retrieval of the next page.
138
     *
139
     * @var array
140
     */
141
    private $searchAfter;
142
143
    /**
144
     * URI parameters alongside Request body search.
145
     *
146
     * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html
147
     *
148
     * @var array
149
     */
150
    private $uriParams = [];
151
152
    /**
153
     * While a search request returns a single “page” of results, the scroll API can be used to retrieve
154
     * large numbers of results (or even all results) from a single search request, in much the same way
155
     * as you would use a cursor on a traditional database. Scrolling is not intended for real time user
156
     * requests, but rather for processing large amounts of data, e.g. in order to reindex the contents
157
     * of one index into a new index with a different configuration.
158
     *
159
     * @var string
160
     */
161
    private $scroll;
162
163
    /**
164
     * @var OrderedSerializer
165
     */
166
    private static $serializer;
167
168
    /**
169
     * @var SearchEndpointInterface[]
170
     */
171
    private $endpoints = [];
172
173
    /**
174
     * Constructor to initialize static properties
175
     */
176
    public function __construct()
177
    {
178
        $this->initializeSerializer();
179
    }
180
181
    /**
182
     * Wakeup method to initialize static properties
183
     */
184
    public function __wakeup()
185
    {
186
        $this->initializeSerializer();
187
    }
188
189
    /**
190
     * Initializes the serializer
191
     */
192
    private function initializeSerializer()
193
    {
194
        if (static::$serializer === null) {
0 ignored issues
show
Bug introduced by
Since $serializer is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $serializer to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
195
            static::$serializer = new OrderedSerializer(
0 ignored issues
show
Bug introduced by
Since $serializer is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $serializer to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
196
                [
197
                    new CustomReferencedNormalizer(),
198
                    new CustomNormalizer(),
199
                ]
200
            );
201
        }
202
    }
203
204
    /**
205
     * Destroys search endpoint.
206
     *
207
     * @param string $type Endpoint type.
208
     */
209
    public function destroyEndpoint($type)
210
    {
211
        unset($this->endpoints[$type]);
212
    }
213
214
    /**
215
     * Adds query to the search.
216
     *
217
     * @param BuilderInterface $query
218
     * @param string           $boolType
219
     * @param string           $key
220
     *
221
     * @return $this
222
     */
223
    public function addQuery(BuilderInterface $query, $boolType = BoolQuery::MUST, $key = null)
224
    {
225
        $endpoint = $this->getEndpoint(QueryEndpoint::NAME);
226
        $endpoint->addToBool($query, $boolType, $key);
0 ignored issues
show
Documentation introduced by
$boolType is of type string, but the function expects a array|null.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Bug introduced by
It seems like $key defined by parameter $key on line 223 can also be of type string; however, ONGR\ElasticsearchDSL\Se...tInterface::addToBool() does only seem to accept array|null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
227
228
        return $this;
229
    }
230
231
    /**
232
     * Returns endpoint instance.
233
     *
234
     * @param string $type Endpoint type.
235
     *
236
     * @return SearchEndpointInterface
237
     */
238
    private function getEndpoint($type)
239
    {
240
        if (!array_key_exists($type, $this->endpoints)) {
241
            $this->endpoints[$type] = SearchEndpointFactory::get($type);
242
        }
243
244
        return $this->endpoints[$type];
245
    }
246
247
    /**
248
     * Returns queries inside BoolQuery instance.
249
     *
250
     * @return BuilderInterface
251
     */
252
    public function getQueries()
253
    {
254
        $endpoint = $this->getEndpoint(QueryEndpoint::NAME);
255
256
        return $endpoint->getBool();
257
    }
258
259
    /**
260
     * Sets query endpoint parameters.
261
     *
262
     * @param array $parameters
263
     *
264
     * @return $this
265
     */
266
    public function setQueryParameters(array $parameters)
267
    {
268
        $this->setEndpointParameters(QueryEndpoint::NAME, $parameters);
269
270
        return $this;
271
    }
272
273
    /**
274
     * Sets parameters to the endpoint.
275
     *
276
     * @param string $endpointName
277
     * @param array  $parameters
278
     */
279
    public function setEndpointParameters($endpointName, array $parameters)
280
    {
281
        /** @var AbstractSearchEndpoint $endpoint */
282
        $endpoint = $this->getEndpoint($endpointName);
283
        $endpoint->setParameters($parameters);
284
    }
285
286
    /**
287
     * Adds a post filter to search.
288
     *
289
     * @param BuilderInterface $filter   Filter.
290
     * @param string           $boolType Example boolType values:
291
     *                                   - must
292
     *                                   - must_not
293
     *                                   - should.
294
     * @param string           $key
295
     *
296
     * @return $this.
0 ignored issues
show
Documentation introduced by
The doc-type $this. could not be parsed: Unknown type name "$this." at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
297
     */
298
    public function addPostFilter(BuilderInterface $filter, $boolType = BoolQuery::MUST, $key = null)
299
    {
300
        $this
301
            ->getEndpoint(PostFilterEndpoint::NAME)
302
            ->addToBool($filter, $boolType, $key);
0 ignored issues
show
Documentation introduced by
$boolType is of type string, but the function expects a array|null.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Bug introduced by
It seems like $key defined by parameter $key on line 298 can also be of type string; however, ONGR\ElasticsearchDSL\Se...tInterface::addToBool() does only seem to accept array|null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
303
304
        return $this;
305
    }
306
307
    /**
308
     * Returns queries inside BoolFilter instance.
309
     *
310
     * @return BuilderInterface
311
     */
312
    public function getPostFilters()
313
    {
314
        $endpoint = $this->getEndpoint(PostFilterEndpoint::NAME);
315
316
        return $endpoint->getBool();
317
    }
318
319
    /**
320
     * Sets post filter endpoint parameters.
321
     *
322
     * @param array $parameters
323
     *
324
     * @return $this
325
     */
326
    public function setPostFilterParameters(array $parameters)
327
    {
328
        $this->setEndpointParameters(PostFilterEndpoint::NAME, $parameters);
329
330
        return $this;
331
    }
332
333
    /**
334
     * Adds aggregation into search.
335
     *
336
     * @param AbstractAggregation $aggregation
337
     *
338
     * @return $this
339
     */
340
    public function addAggregation(AbstractAggregation $aggregation)
341
    {
342
        $this->getEndpoint(AggregationsEndpoint::NAME)->add($aggregation, $aggregation->getName());
343
344
        return $this;
345
    }
346
347
    /**
348
     * Returns all aggregations.
349
     *
350
     * @return BuilderInterface[]
351
     */
352
    public function getAggregations()
353
    {
354
        return $this->getEndpoint(AggregationsEndpoint::NAME)->getAll();
355
    }
356
357
    /**
358
     * Adds inner hit into search.
359
     *
360
     * @param NestedInnerHit $innerHit
361
     *
362
     * @return $this
363
     */
364
    public function addInnerHit(NestedInnerHit $innerHit)
365
    {
366
        $this->getEndpoint(InnerHitsEndpoint::NAME)->add($innerHit, $innerHit->getName());
367
368
        return $this;
369
    }
370
371
    /**
372
     * Returns all inner hits.
373
     *
374
     * @return BuilderInterface[]
375
     */
376
    public function getInnerHits()
377
    {
378
        return $this->getEndpoint(InnerHitsEndpoint::NAME)->getAll();
379
    }
380
381
    /**
382
     * Adds sort to search.
383
     *
384
     * @param BuilderInterface $sort
385
     *
386
     * @return $this
387
     */
388
    public function addSort(BuilderInterface $sort)
389
    {
390
        $this->getEndpoint(SortEndpoint::NAME)->add($sort);
391
392
        return $this;
393
    }
394
395
    /**
396
     * Returns all set sorts.
397
     *
398
     * @return BuilderInterface[]
399
     */
400
    public function getSorts()
401
    {
402
        return $this->getEndpoint(SortEndpoint::NAME)->getAll();
403
    }
404
405
    /**
406
     * Allows to highlight search results on one or more fields.
407
     *
408
     * @param Highlight $highlight
409
     *
410
     * @return $this.
0 ignored issues
show
Documentation introduced by
The doc-type $this. could not be parsed: Unknown type name "$this." at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
411
     */
412
    public function addHighlight($highlight)
413
    {
414
        $this->getEndpoint(HighlightEndpoint::NAME)->add($highlight);
415
416
        return $this;
417
    }
418
419
    /**
420
     * Returns highlight builder.
421
     *
422
     * @return BuilderInterface
423
     */
424
    public function getHighlights()
425
    {
426
        /** @var HighlightEndpoint $highlightEndpoint */
427
        $highlightEndpoint = $this->getEndpoint(HighlightEndpoint::NAME);
428
429
        return $highlightEndpoint->getHighlight();
430
    }
431
432
    /**
433
    * Adds suggest into search.
434
    *
435
    * @param BuilderInterface $suggest
436
    *
437
    * @return $this
438
    */
439
    public function addSuggest(NamedBuilderInterface $suggest)
440
    {
441
        $this->getEndpoint(SuggestEndpoint::NAME)->add($suggest, $suggest->getName());
0 ignored issues
show
Documentation introduced by
$suggest->getName() is of type string, but the function expects a array|null.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
442
443
        return $this;
444
    }
445
446
    /**
447
    * Returns all suggests.
448
    *
449
    * @return BuilderInterface[]
450
    */
451
    public function getSuggests()
452
    {
453
        return $this->getEndpoint(SuggestEndpoint::NAME)->getAll();
454
    }
455
456
    /**
457
     * @return int
458
     */
459
    public function getFrom()
460
    {
461
        return $this->from;
462
    }
463
464
    /**
465
     * @param int $from
466
     * @return $this
467
     */
468
    public function setFrom($from)
469
    {
470
        $this->from = $from;
471
        return $this;
472
    }
473
474
    /**
475
     * @return bool
476
     */
477
    public function isTrackTotalHits()
478
    {
479
        return $this->trackTotalHits;
480
    }
481
482
    /**
483
     * @param bool $trackTotalHits
484
     * @return $this
485
     */
486
    public function setTrackTotalHits(bool $trackTotalHits)
487
    {
488
        $this->trackTotalHits = $trackTotalHits;
489
        return $this;
490
    }
491
492
    /**
493
     * @return int
494
     */
495
    public function getSize()
496
    {
497
        return $this->size;
498
    }
499
500
    /**
501
     * @param int $size
502
     * @return $this
503
     */
504
    public function setSize($size)
505
    {
506
        $this->size = $size;
507
        return $this;
508
    }
509
510
    /**
511
     * @return bool
512
     */
513
    public function isSource()
514
    {
515
        return $this->source;
516
    }
517
518
    /**
519
     * @param bool $source
520
     * @return $this
521
     */
522
    public function setSource($source)
523
    {
524
        $this->source = $source;
525
        return $this;
526
    }
527
528
    /**
529
     * @return array
530
     */
531
    public function getStoredFields()
532
    {
533
        return $this->storedFields;
534
    }
535
536
    /**
537
     * @param array $storedFields
538
     * @return $this
539
     */
540
    public function setStoredFields($storedFields)
541
    {
542
        $this->storedFields = $storedFields;
543
        return $this;
544
    }
545
546
    /**
547
     * @return array
548
     */
549
    public function getScriptFields()
550
    {
551
        return $this->scriptFields;
552
    }
553
554
    /**
555
     * @param array $scriptFields
556
     * @return $this
557
     */
558
    public function setScriptFields($scriptFields)
559
    {
560
        $this->scriptFields = $scriptFields;
561
        return $this;
562
    }
563
564
    /**
565
     * @return array
566
     */
567
    public function getDocValueFields()
568
    {
569
        return $this->docValueFields;
570
    }
571
572
    /**
573
     * @param array $docValueFields
574
     * @return $this
575
     */
576
    public function setDocValueFields($docValueFields)
577
    {
578
        $this->docValueFields = $docValueFields;
579
        return $this;
580
    }
581
582
    /**
583
     * @return bool
584
     */
585
    public function isExplain()
586
    {
587
        return $this->explain;
588
    }
589
590
    /**
591
     * @param bool $explain
592
     * @return $this
593
     */
594
    public function setExplain($explain)
595
    {
596
        $this->explain = $explain;
597
        return $this;
598
    }
599
600
    /**
601
     * @return bool
602
     */
603
    public function isVersion()
604
    {
605
        return $this->version;
606
    }
607
608
    /**
609
     * @param bool $version
610
     * @return $this
611
     */
612
    public function setVersion($version)
613
    {
614
        $this->version = $version;
615
        return $this;
616
    }
617
618
    /**
619
     * @return array
620
     */
621
    public function getIndicesBoost()
622
    {
623
        return $this->indicesBoost;
624
    }
625
626
    /**
627
     * @param array $indicesBoost
628
     * @return $this
629
     */
630
    public function setIndicesBoost($indicesBoost)
631
    {
632
        $this->indicesBoost = $indicesBoost;
633
        return $this;
634
    }
635
636
    /**
637
     * @return int
638
     */
639
    public function getMinScore()
640
    {
641
        return $this->minScore;
642
    }
643
644
    /**
645
     * @param int $minScore
646
     * @return $this
647
     */
648
    public function setMinScore($minScore)
649
    {
650
        $this->minScore = $minScore;
651
        return $this;
652
    }
653
654
    /**
655
     * @return array
656
     */
657
    public function getSearchAfter()
658
    {
659
        return $this->searchAfter;
660
    }
661
662
    /**
663
     * @param array $searchAfter
664
     * @return $this
665
     */
666
    public function setSearchAfter($searchAfter)
667
    {
668
        $this->searchAfter = $searchAfter;
669
        return $this;
670
    }
671
672
    /**
673
     * @return string
674
     */
675
    public function getScroll()
676
    {
677
        return $this->scroll;
678
    }
679
680
    /**
681
     * @param string $scroll
682
     * @return $this
683
     */
684
    public function setScroll($scroll = '5m')
685
    {
686
        $this->scroll = $scroll;
687
688
        $this->addUriParam('scroll', $this->scroll);
689
690
        return $this;
691
    }
692
693
    /**
694
     * @param string $name
695
     * @param string|array|bool $value
696
     *
697
     * @return $this
698
     */
699
    public function addUriParam($name, $value)
700
    {
701
        if (in_array($name, [
702
            'q',
703
            'df',
704
            'analyzer',
705
            'analyze_wildcard',
706
            'default_operator',
707
            'lenient',
708
            'explain',
709
            '_source',
710
            '_source_exclude',
711
            '_source_include',
712
            'stored_fields',
713
            'sort',
714
            'track_scores',
715
            'timeout',
716
            'terminate_after',
717
            'from',
718
            'size',
719
            'search_type',
720
            'scroll',
721
            'allow_no_indices',
722
            'ignore_unavailable',
723
            'typed_keys',
724
            'pre_filter_shard_size',
725
            'ignore_unavailable',
726
        ])) {
727
            $this->uriParams[$name] = $value;
728
        } else {
729
            throw new \InvalidArgumentException(sprintf('Parameter %s is not supported.', $value));
730
        }
731
732
        return $this;
733
    }
734
735
    /**
736
     * Returns query url parameters.
737
     *
738
     * @return array
739
     */
740
    public function getUriParams()
741
    {
742
        return $this->uriParams;
743
    }
744
745
    /**
746
     * {@inheritdoc}
747
     */
748
    public function toArray()
749
    {
750
        $output = array_filter(static::$serializer->normalize($this->endpoints));
0 ignored issues
show
Bug introduced by
Since $serializer is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $serializer to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
751
752
        $params = [
753
            'from' => 'from',
754
            'size' => 'size',
755
            'source' => '_source',
756
            'storedFields' => 'stored_fields',
757
            'scriptFields' => 'script_fields',
758
            'docValueFields' => 'docvalue_fields',
759
            'explain' => 'explain',
760
            'version' => 'version',
761
            'indicesBoost' => 'indices_boost',
762
            'minScore' => 'min_score',
763
            'searchAfter' => 'search_after',
764
            'trackTotalHits' => 'track_total_hits',
765
        ];
766
767
        foreach ($params as $field => $param) {
768
            if ($this->$field !== null) {
769
                $output[$param] = $this->$field;
770
            }
771
        }
772
773
        return $output;
774
    }
775
}
776