-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTerm.php
More file actions
84 lines (61 loc) · 1.52 KB
/
Term.php
File metadata and controls
84 lines (61 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php declare(strict_types = 1);
namespace Spameri\ElasticQuery\Aggregation;
/**
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
*/
class Term implements LeafAggregationInterface
{
private string $field;
private int $size;
private ?int $missing;
private ?string $key;
private \Spameri\ElasticQuery\Aggregation\Terms\OrderCollection $order;
private ?string $include;
private ?string $exclude;
public function __construct(
string $field,
int $size = 0,
int $missing = NULL,
?\Spameri\ElasticQuery\Aggregation\Terms\OrderCollection $order = NULL,
?string $include = NULL,
?string $exclude = NULL,
?string $key = NULL
)
{
$this->field = $field;
$this->size = $size;
$this->missing = $missing;
$this->key = $key;
$this->order = $order ?? new \Spameri\ElasticQuery\Aggregation\Terms\OrderCollection();
$this->include = $include;
$this->exclude = $exclude;
}
public function key(): string
{
return $this->key ?? $this->field;
}
public function toArray(): array
{
$array = [
'field' => $this->field,
];
if ($this->size > 0) {
$array['size'] = $this->size;
}
if ($this->missing !== NULL) {
$array['missing'] = $this->missing;
}
if (\count($this->order)) {
$array['order'] = $this->order->toArray();
}
if ($this->include !== NULL) {
$array['include'] = $this->include;
}
if ($this->exclude !== NULL) {
$array['exclude'] = $this->exclude;
}
return [
'terms' => $array,
];
}
}