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\Bucketing; |
13
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation; |
15
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class representing geohash grid aggregation. |
19
|
|
|
* |
20
|
|
|
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html |
21
|
|
|
*/ |
22
|
|
|
class GeoHashGridAggregation extends AbstractAggregation |
23
|
|
|
{ |
24
|
|
|
use BucketingTrait; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var int |
28
|
|
|
*/ |
29
|
|
|
private $precision; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var int |
33
|
|
|
*/ |
34
|
|
|
private $size; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var int |
38
|
|
|
*/ |
39
|
|
|
private $shardSize; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Inner aggregations container init. |
43
|
|
|
* |
44
|
|
|
* @param string $name |
45
|
|
|
* @param string $field |
46
|
|
|
* @param int $precision |
47
|
|
|
* @param int $size |
48
|
|
|
* @param int $shardSize |
49
|
|
|
*/ |
50
|
|
|
public function __construct($name, $field = null, $precision = null, $size = null, $shardSize = null) |
51
|
|
|
{ |
52
|
|
|
parent::__construct($name); |
53
|
|
|
|
54
|
|
|
$this->setField($field); |
55
|
|
|
$this->setPrecision($precision); |
56
|
|
|
$this->setSize($size); |
57
|
|
|
$this->setShardSize($shardSize); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return int |
62
|
|
|
*/ |
63
|
|
|
public function getPrecision() |
64
|
|
|
{ |
65
|
|
|
return $this->precision; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param int $precision |
70
|
|
|
* |
71
|
|
|
* @return $this |
72
|
|
|
*/ |
73
|
|
|
public function setPrecision($precision) |
74
|
|
|
{ |
75
|
|
|
$this->precision = $precision; |
76
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return int |
82
|
|
|
*/ |
83
|
|
|
public function getSize() |
84
|
|
|
{ |
85
|
|
|
return $this->size; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param int $size |
90
|
|
|
* |
91
|
|
|
* @return $this |
92
|
|
|
*/ |
93
|
|
|
public function setSize($size) |
94
|
|
|
{ |
95
|
|
|
$this->size = $size; |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return int |
102
|
|
|
*/ |
103
|
|
|
public function getShardSize() |
104
|
|
|
{ |
105
|
|
|
return $this->shardSize; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param int $shardSize |
110
|
|
|
* |
111
|
|
|
* @return $this |
112
|
|
|
*/ |
113
|
|
|
public function setShardSize($shardSize) |
114
|
|
|
{ |
115
|
|
|
$this->shardSize = $shardSize; |
116
|
|
|
|
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* {@inheritdoc} |
122
|
|
|
*/ |
123
|
|
|
public function getArray() |
124
|
|
|
{ |
125
|
|
|
$data = []; |
126
|
|
|
|
127
|
|
|
if ($this->getField()) { |
128
|
|
|
$data['field'] = $this->getField(); |
129
|
|
|
} else { |
130
|
|
|
throw new \LogicException('Geo bounds aggregation must have a field set.'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
if ($this->getPrecision()) { |
134
|
|
|
$data['precision'] = $this->getPrecision(); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
if ($this->getSize()) { |
138
|
|
|
$data['size'] = $this->getSize(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
if ($this->getShardSize()) { |
142
|
|
|
$data['shard_size'] = $this->getShardSize(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return $data; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* {@inheritdoc} |
150
|
|
|
*/ |
151
|
|
|
public function getType() |
152
|
|
|
{ |
153
|
|
|
return 'geohash_grid'; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|