Skip to content
Snippets Groups Projects
Commit c0b75cf1 authored by Mantas Jonušas's avatar Mantas Jonušas
Browse files

Implemented addQuery method in SpanOr and SpanNear queries

parent 752a57f1
No related branches found
No related tags found
No related merge requests found
......@@ -11,37 +11,30 @@
namespace ONGR\ElasticsearchBundle\DSL\Query\Span;
use ONGR\ElasticsearchBundle\DSL\ParametersTrait;
/**
* Elasticsearch span near query.
*/
class SpanNearQuery implements SpanQueryInterface
class SpanNearQuery extends SpanOrQuery implements SpanQueryInterface
{
use ParametersTrait;
/**
* @var int
*/
private $slop;
/**
* @var SpanQueryInterface[]
* @return int
*/
private $queries = [];
public function getSlop()
{
return $this->slop;
}
/**
* @param int $slop
* @param SpanQueryInterface[] $queries
* @param array $parameters
*
* @throws \LogicException
* @param int $slop
*/
public function __construct($slop, array $queries = [], array $parameters = [])
public function setSlop($slop)
{
$this->slop = $slop;
$this->queries = $queries;
$this->setParameters($parameters);
}
/**
......@@ -58,11 +51,10 @@ class SpanNearQuery implements SpanQueryInterface
public function toArray()
{
$query = [];
foreach ($this->queries as $type) {
$data = [$type->getType() => $type->toArray()];
$query['clauses'][] = $data;
foreach ($this->getQueries() as $type) {
$query['clauses'][] = [$type->getType() => $type->toArray()];
}
$query['slop'] = $this->slop;
$query['slop'] = $this->getSlop();
$output = $this->processArray($query);
return $output;
......
......@@ -26,17 +26,35 @@ class SpanOrQuery implements SpanQueryInterface
private $queries = [];
/**
* @param SpanQueryInterface[] $queries
* @param array $parameters
* @param array $parameters
*/
public function __construct(array $queries = [], array $parameters = [])
public function __construct(array $parameters = [])
{
foreach ($queries as $query) {
$this->queries[] = $query;
}
$this->setParameters($parameters);
}
/**
* Add span query.
*
* @param SpanQueryInterface $query
*
* @return $this
*/
public function addQuery(SpanQueryInterface $query)
{
$this->queries[] = $query;
return $this;
}
/**
* @return SpanQueryInterface[]
*/
public function getQueries()
{
return $this->queries;
}
/**
* {@inheritdoc}
*/
......@@ -52,8 +70,7 @@ class SpanOrQuery implements SpanQueryInterface
{
$query = [];
foreach ($this->queries as $type) {
$data = [$type->getType() => $type->toArray()];
$query['clauses'][] = $data;
$query['clauses'][] = [$type->getType() => $type->toArray()];
}
$output = $this->processArray($query);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment