|
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
|
|
|
public function setPrecision($precision) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->precision = $precision; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return int |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getSize() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->size; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param int $size |
|
86
|
|
|
*/ |
|
87
|
|
|
public function setSize($size) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->size = $size; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return int |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getShardSize() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->shardSize; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param int $shardSize |
|
102
|
|
|
*/ |
|
103
|
|
|
public function setShardSize($shardSize) |
|
104
|
|
|
{ |
|
105
|
|
|
$this->shardSize = $shardSize; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* {@inheritdoc} |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getArray() |
|
112
|
|
|
{ |
|
113
|
|
|
$data = []; |
|
114
|
|
|
|
|
115
|
|
|
if ($this->getField()) { |
|
116
|
|
|
$data['field'] = $this->getField(); |
|
117
|
|
|
} else { |
|
118
|
|
|
throw new \LogicException('Geo bounds aggregation must have a field set.'); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
if ($this->getPrecision()) { |
|
122
|
|
|
$data['precision'] = $this->getPrecision(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
if ($this->getSize()) { |
|
126
|
|
|
$data['size'] = $this->getSize(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
if ($this->getShardSize()) { |
|
130
|
|
|
$data['shard_size'] = $this->getShardSize(); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return $data; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* {@inheritdoc} |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getType() |
|
140
|
|
|
{ |
|
141
|
|
|
return 'geohash_grid'; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|