diff --git a/Query/Span/SpanNearQuery.php b/Query/Span/SpanNearQuery.php index 48047645b4540a768d754c5ddc569708b903e93f..564a2ca033e51c41a0bb10641c5267b8169c3dd5 100644 --- a/Query/Span/SpanNearQuery.php +++ b/Query/Span/SpanNearQuery.php @@ -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; diff --git a/Query/Span/SpanOrQuery.php b/Query/Span/SpanOrQuery.php index a18df02cdd078b1ac15d790a69e2898f5506d7fb..5d351c40cebca6be93d09963abb11baac4a8481a 100644 --- a/Query/Span/SpanOrQuery.php +++ b/Query/Span/SpanOrQuery.php @@ -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);