Skip to content

Commit 63822cf

Browse files
committed
RangeValue aggregation tweak
this aggregation can only do > or < comparison, with this you can use >= or <= just because of $int++.
1 parent 24e123a commit 63822cf

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/Aggregation/RangeValue.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,30 @@ class RangeValue implements \Spameri\ElasticQuery\Entity\EntityInterface
2121
*/
2222
private $to;
2323

24+
/**
25+
* @var bool
26+
*/
27+
private $fromEqual;
28+
29+
/**
30+
* @var bool
31+
*/
32+
private $toEqual;
33+
2434

2535
public function __construct(
26-
string $key
27-
, int $from
28-
, int $to
36+
string $key,
37+
int $from,
38+
int $to,
39+
bool $fromEqual = TRUE,
40+
bool $toEqual = TRUE
2941
)
3042
{
3143
$this->key = $key;
3244
$this->from = $from;
3345
$this->to = $to;
46+
$this->fromEqual = $fromEqual;
47+
$this->toEqual = $toEqual;
3448
}
3549

3650

@@ -42,10 +56,20 @@ public function key(): string
4256

4357
public function toArray(): array
4458
{
59+
$from = $this->from;
60+
$to = $this->to;
61+
62+
if ( ! $this->fromEqual) {
63+
$from++;
64+
}
65+
if ($this->toEqual) {
66+
$to++;
67+
}
68+
4569
return [
4670
'key' => $this->key,
47-
'from' => $this->from,
48-
'to' => $this->to,
71+
'from' => $from,
72+
'to' => $to,
4973
];
5074
}
5175

0 commit comments

Comments
 (0)