|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace ONGR\ElasticsearchDSL\Aggregation\Bucketing; |
|
15
|
|
|
|
|
16
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation; |
|
17
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class representing geohash grid aggregation. |
|
21
|
|
|
* |
|
22
|
|
|
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html |
|
23
|
|
|
*/ |
|
24
|
|
|
class GeoHashGridAggregation extends AbstractAggregation |
|
25
|
|
|
{ |
|
26
|
|
|
use BucketingTrait; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct( |
|
29
|
|
|
private string $name, |
|
|
|
|
|
|
30
|
|
|
private ?string $field = null, |
|
31
|
|
|
private ?int $precision = null, |
|
32
|
|
|
private ?int $size = null, |
|
33
|
|
|
private ?int $shardSize = null |
|
34
|
|
|
) { |
|
35
|
|
|
parent::__construct($name); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getPrecision(): ?int |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->precision; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function setPrecision(?int $precision): static |
|
44
|
|
|
{ |
|
45
|
|
|
$this->precision = $precision; |
|
46
|
|
|
|
|
47
|
|
|
return $this; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getSize(): ?int |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->size; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function setSize(?int $size): static |
|
56
|
|
|
{ |
|
57
|
|
|
$this->size = $size; |
|
58
|
|
|
|
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getShardSize(): ?int |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->shardSize; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function setShardSize(?int $shardSize): static |
|
68
|
|
|
{ |
|
69
|
|
|
$this->shardSize = $shardSize; |
|
70
|
|
|
|
|
71
|
|
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getArray(): array |
|
75
|
|
|
{ |
|
76
|
|
|
$data = []; |
|
77
|
|
|
|
|
78
|
|
|
if ($this->getField()) { |
|
79
|
|
|
$data['field'] = $this->getField(); |
|
80
|
|
|
} else { |
|
81
|
|
|
throw new \LogicException('Geo bounds aggregation must have a field set.'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
if ($this->getPrecision()) { |
|
85
|
|
|
$data['precision'] = $this->getPrecision(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if ($this->getSize()) { |
|
89
|
|
|
$data['size'] = $this->getSize(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if ($this->getShardSize()) { |
|
93
|
|
|
$data['shard_size'] = $this->getShardSize(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $data; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function getType(): string |
|
100
|
|
|
{ |
|
101
|
|
|
return 'geohash_grid'; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|