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
|
|
|
use Traits\ShardSizeTrait; |
13
|
|
|
|
14
|
|
|
public const DEFAULT_PRECISION_VALUE = 5; |
15
|
|
|
public const DEFAULT_SIZE_VALUE = 10000; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param string $name the name of this aggregation |
19
|
|
|
* @param string $field the field on which to perform this aggregation |
20
|
|
|
*/ |
21
|
|
|
public function __construct(string $name, string $field) |
22
|
|
|
{ |
23
|
|
|
parent::__construct($name); |
24
|
|
|
$this->setField($field); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Set the field for this aggregation. |
29
|
|
|
* |
30
|
|
|
* @param string $field the name of the document field on which to perform this aggregation |
31
|
|
|
* |
32
|
|
|
* @return $this |
33
|
|
|
*/ |
34
|
|
|
public function setField(string $field): self |
35
|
|
|
{ |
36
|
|
|
return $this->setParam('field', $field); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Set the precision for this aggregation. |
41
|
|
|
* |
42
|
|
|
* @param int|string $precision an integer between 1 and 12, inclusive. Defaults to 5 or distance like 1km, 10m |
43
|
|
|
* |
44
|
|
|
* @return $this |
45
|
|
|
*/ |
46
|
|
|
public function setPrecision($precision): self |
47
|
|
|
{ |
48
|
|
|
if (!\is_int($precision) && !\is_string($precision)) { |
49
|
|
|
throw new \TypeError(\sprintf('Argument 1 passed to "%s()" must be a int or string, %s given.', __METHOD__, \is_object($precision) ? \get_class($precision) : \gettype($precision))); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $this->setParam('precision', $precision); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Set the precision for this aggregation in meters or kilometers. |
57
|
|
|
* |
58
|
|
|
* @param string $precision a string like 100m or 1km |
59
|
|
|
* |
60
|
|
|
* @return $this |
61
|
|
|
*/ |
62
|
|
|
public function setDistancePrecision(string $precision): self |
63
|
|
|
{ |
64
|
|
|
return $this->setParam('precision', $precision); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Set the maximum number of buckets to return. |
69
|
|
|
* |
70
|
|
|
* @param int $size defaults to 10,000 |
71
|
|
|
* |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
|
|
public function setSize(int $size): self |
75
|
|
|
{ |
76
|
|
|
return $this->setParam('size', $size); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.