1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Elastica\Aggregation; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class GeohashGrid. |
7
|
|
|
* |
8
|
|
|
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html |
9
|
|
|
*/ |
10
|
|
|
class GeohashGrid extends AbstractAggregation |
11
|
|
|
{ |
12
|
|
|
public const DEFAULT_PRECISION_VALUE = 5; |
13
|
|
|
public const DEFAULT_SIZE_VALUE = 10000; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @param string $name the name of this aggregation |
17
|
|
|
* @param string $field the field on which to perform this aggregation |
18
|
|
|
*/ |
19
|
|
|
public function __construct(string $name, string $field) |
20
|
|
|
{ |
21
|
|
|
parent::__construct($name); |
22
|
|
|
$this->setField($field); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Set the field for this aggregation. |
27
|
|
|
* |
28
|
|
|
* @param string $field the name of the document field on which to perform this aggregation |
29
|
|
|
* |
30
|
|
|
* @return $this |
31
|
|
|
*/ |
32
|
|
|
public function setField(string $field): self |
33
|
|
|
{ |
34
|
|
|
return $this->setParam('field', $field); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Set the precision for this aggregation. |
39
|
|
|
* |
40
|
|
|
* @param int $precision an integer between 1 and 12, inclusive. Defaults to 5. |
41
|
|
|
* |
42
|
|
|
* @return $this |
43
|
|
|
*/ |
44
|
|
|
public function setPrecision(int $precision): self |
45
|
|
|
{ |
46
|
|
|
return $this->setParam('precision', $precision); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Set the precision for this aggregation in meters or kilometers. |
51
|
|
|
* |
52
|
|
|
* @param string $precision a string like 100m or 1km |
53
|
|
|
* |
54
|
|
|
* @return $this |
55
|
|
|
*/ |
56
|
|
|
public function setDistancePrecision(string $precision): self |
57
|
|
|
{ |
58
|
|
|
return $this->setParam('precision', $precision); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Set the maximum number of buckets to return. |
63
|
|
|
* |
64
|
|
|
* @param int $size defaults to 10,000 |
65
|
|
|
* |
66
|
|
|
* @return $this |
67
|
|
|
*/ |
68
|
|
|
public function setSize(int $size): self |
69
|
|
|
{ |
70
|
|
|
return $this->setParam('size', $size); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Set the number of results returned from each shard. |
75
|
|
|
* |
76
|
|
|
* @return $this |
77
|
|
|
*/ |
78
|
|
|
public function setShardSize(int $shardSize): self |
79
|
|
|
{ |
80
|
|
|
return $this->setParam('shard_size', $shardSize); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|