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\Aggregation\Matrix; |
13
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation; |
15
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class representing Max Aggregation. |
19
|
|
|
* |
20
|
|
|
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html |
21
|
|
|
*/ |
22
|
|
|
class MaxAggregation extends AbstractAggregation |
23
|
|
|
{ |
24
|
|
|
use MetricTrait; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string Used for multi value aggregation fields to pick a value. |
28
|
|
|
*/ |
29
|
|
|
private $mode; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array Defines how documents that are missing a value should be treated. |
33
|
|
|
*/ |
34
|
|
|
private $missing; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Inner aggregations container init. |
38
|
|
|
* |
39
|
|
|
* @param string $name |
40
|
|
|
* @param string|array $field Fields list to aggregate. |
41
|
|
|
* @param array $missing |
42
|
|
|
* @param string $mode |
43
|
|
|
*/ |
44
|
|
|
public function __construct($name, $field, $missing = null, $mode = null) |
45
|
|
|
{ |
46
|
|
|
parent::__construct($name); |
47
|
|
|
|
48
|
|
|
$this->setField($field); |
|
|
|
|
49
|
|
|
$this->setMode($mode); |
50
|
|
|
$this->missing = $missing; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getMode() |
57
|
|
|
{ |
58
|
|
|
return $this->mode; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $mode |
63
|
|
|
* |
64
|
|
|
* @return $this |
65
|
|
|
*/ |
66
|
|
|
public function setMode($mode) |
67
|
|
|
{ |
68
|
|
|
$this->mode = $mode; |
69
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
public function getMissing() |
77
|
|
|
{ |
78
|
|
|
return $this->missing; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param array $missing |
83
|
|
|
* |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
|
|
public function setMissing($missing) |
87
|
|
|
{ |
88
|
|
|
$this->missing = $missing; |
89
|
|
|
|
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
*/ |
96
|
|
|
public function getType() |
97
|
|
|
{ |
98
|
|
|
return 'matrix_stats'; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
protected function getArray() |
102
|
|
|
{ |
103
|
|
|
$out = []; |
104
|
|
|
if ($this->getField()) { |
105
|
|
|
$out['fields'] = $this->getField(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if ($this->getMode()) { |
109
|
|
|
$out['mode'] = $this->getMode(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
if ($this->getMissing()) { |
114
|
|
|
$out['missing'] = $this->getMissing(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return $out; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
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.