diff --git a/src/Domain/Syntax/Around.php b/src/Domain/Syntax/Around.php new file mode 100644 index 0000000..8e2b029 --- /dev/null +++ b/src/Domain/Syntax/Around.php @@ -0,0 +1,46 @@ +field = $field; + $this->value = $value; + $this->tolerance = $tolerance; + $this->percentage = $percentage; + $this->date = $date; + $this->boost = $boost; + } + + public function build(): array { + if ($this->date) { + $days = (int) $this->tolerance; + $lte = date('Y-m-d H:i:s', strtotime("+{$days} day", strtotime($this->value))); + $gte = date('Y-m-d H:i:s', strtotime("-{$days} day", strtotime($this->value))); + } else { + $modifier = $this->percentage ? $this->value * $this->tolerance : $this->tolerance; + $lte = $this->value + $modifier; + $gte = $this->value - $modifier; + } + + return ['range' => [ + $this->field => ['lte' => $lte, 'gte' => $gte, 'boost' => $this->boost], + ]]; + } +}