Newer
Older
<?php
namespace IQDEV\ElasticSearch\Search;
use IQDEV\ElasticSearch\Esable;
use IQDEV\ElasticSearch\Search\Aggs\AggsCollection;
use IQDEV\ElasticSearch\Search\BoolQuery\Query;
final class Request implements Esable
{
private ?Query $query = null;
private ?Query $postFilter = null;
private ?AggsCollection $aggs = null;
private ?Pagination $pagination = null;
public function setPagination(?Pagination $pagination): self
{
$this->pagination = $pagination;
return $this;
}
public function getQuery(): Query
{
$this->query = new Query();
}
return $this->query;
}
public function getPostFilter(): Query
{
$this->postFilter = new Query();
}
return $this->postFilter;
}
public function getAggs(): AggsCollection
{
$this->aggs = new AggsCollection();
}
return $this->aggs;
}
public function getPagination(): ?Pagination
{
return $this->pagination;
}
public function addMatch(string $key, array $param): self
public function getSort(): OrderCollection
{
if (null === $this->sort) {
$this->sort = new OrderCollection();
}
return $this->sort;
}
$request = [];
if ($this->source) {
$request['_source'] = $this->source;
}
if ($this->postFilter && false === $this->postFilter->isEmpty()) {
if ($this->query && false === $this->query->isEmpty()) {
foreach ($this->match as $key => $value) {
$request['query']['match'][$key] = $value;
}
}
if ($this->aggs) {
$request['aggs'] = $this->aggs->es()['aggs'];
}
if ($this->pagination) {
$request = array_merge($request, $this->pagination->es());
}
if ($this->sort) {
$request['sort'] = $this->sort->es();