You need to sign in or sign up before continuing.
Newer
Older
<?php
namespace IQDEV\ElasticSearch\Search;
use IQDEV\ElasticSearch\Esable;
use IQDEV\ElasticSearch\Criteria\Match\QueryMatchCollection;
use IQDEV\ElasticSearch\Criteria\Order\OrderCollection;
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;
private ?QueryMatchCollection $matchCollection = null;
public function setPagination(?Pagination $pagination): self
{
$this->pagination = $pagination;
return $this;
}
public function getQuery(): Query
{
public function setQuery(Query $query): self
{
$this->query = $query;
return $this;
}
$this->postFilter = new Query();
}
return $this->postFilter;
}
public function setPostFilter(Query $query): self
{
$this->postFilter = $query;
return $this;
}
public function setAggs(AggsCollection $aggs): self
$this->aggs = $aggs;
return $this;
public function getQueryMatch(): QueryMatchCollection
if (null === $this->matchCollection) {
$this->matchCollection = new QueryMatchCollection();
}
return $this->matchCollection;
}
public function getPagination(): ?Pagination
{
return $this->pagination;
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()) {
if ($this->matchCollection && false === $this->matchCollection->isEmpty()) {
$request['query']['match'] = $this->matchCollection->es();
}
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();