diff --git a/Filter/HasChildFilter.php b/Filter/HasChildFilter.php index cb8afae97ed19a6ce4af5df0cbaa492fb8af5907..5310923a5195f3de4fbebd1f98cb231902b84899 100644 --- a/Filter/HasChildFilter.php +++ b/Filter/HasChildFilter.php @@ -21,19 +21,14 @@ class HasChildFilter implements BuilderInterface { use ParametersTrait; - const INNER_QUERY = 'query'; - const INNER_FILTER = 'filter'; + const USE_QUERY = 'query'; + const USE_FILTER = 'filter'; /** * @var string */ private $type; - /** - * @var BuilderInterface - */ - private $filter; - /** * @var BuilderInterface */ @@ -41,27 +36,17 @@ class HasChildFilter implements BuilderInterface /** * @param string $type - * @param BuilderInterface $block + * @param BuilderInterface $query * @param array $parameters - * @param string $inner + * @param string $dslType * * @throws \InvalidArgumentException */ - public function __construct($type, BuilderInterface $block, array $parameters = [], $inner = self::INNER_FILTER) + public function __construct($type, BuilderInterface $query, array $parameters = [], $dslType = self::USE_FILTER) { $this->type = $type; - - switch ($inner) { - case 'filter': - $this->filter = $block; - break; - case 'query': - $this->query = $block; - break; - default: - throw new \InvalidArgumentException('Not supported argument type'); - } - + $this->dslType = $dslType; + $this->query = $query; $this->setParameters($parameters); } @@ -78,17 +63,10 @@ class HasChildFilter implements BuilderInterface */ public function toArray() { - $query = [ 'type' => $this->type ]; - - $queries = ['filter', 'query']; - - foreach ($queries as $type) { - if ($this->{$type}) { - $query[$type] = [ - $this->{$type}->getType() => $this->{$type}->toArray(), - ]; - } - } + $query = [ + 'type' => $this->type, + $this->dslType => [$this->query->getType() => $this->query->toArray()], + ]; $output = $this->processArray($query); diff --git a/Filter/HasParentFilter.php b/Filter/HasParentFilter.php index d81dce27febf8f834bf4e4ffd7d138dab9824abe..d151c41eeed8d6cd4facc4d5fce762ec9ad68917 100644 --- a/Filter/HasParentFilter.php +++ b/Filter/HasParentFilter.php @@ -21,19 +21,14 @@ class HasParentFilter implements BuilderInterface { use ParametersTrait; - const INNER_QUERY = 'query'; - const INNER_FILTER = 'filter'; + const USE_QUERY = 'query'; + const USE_FILTER = 'filter'; /** * @var string */ private $parentType; - /** - * @var BuilderInterface - */ - private $filter; - /** * @var BuilderInterface */ @@ -41,31 +36,21 @@ class HasParentFilter implements BuilderInterface /** * @param string $parentType - * @param BuilderInterface $block + * @param BuilderInterface $query * @param array $parameters - * @param string $inner + * @param string $dslType * * @throws \InvalidArgumentException */ public function __construct( $parentType, - BuilderInterface $block, + BuilderInterface $query, array $parameters = [], - $inner = self::INNER_FILTER + $dslType = self::USE_FILTER ) { $this->parentType = $parentType; - - switch ($inner) { - case 'filter': - $this->filter = $block; - break; - case 'query': - $this->query = $block; - break; - default: - throw new \InvalidArgumentException('Not supported argument type'); - } - + $this->dslType = $dslType; + $this->query = $query; $this->setParameters($parameters); } @@ -82,17 +67,10 @@ class HasParentFilter implements BuilderInterface */ public function toArray() { - $query = [ 'parent_type' => $this->parentType ]; - - $queries = ['filter', 'query']; - - foreach ($queries as $type) { - if ($this->{$type}) { - $query[$type] = [ - $this->{$type}->getType() => $this->{$type}->toArray(), - ]; - } - } + $query = [ + 'parent_type' => $this->parentType, + $this->dslType => [$this->query->getType() => $this->query->toArray()], + ]; $output = $this->processArray($query); diff --git a/Query/ConstantScoreQuery.php b/Query/ConstantScoreQuery.php index 33990de75707605a039dedcf32d2c2de8fdb3f17..3eb19c136fee47eaef5d341893674eb4ca7d7bfe 100644 --- a/Query/ConstantScoreQuery.php +++ b/Query/ConstantScoreQuery.php @@ -21,6 +21,9 @@ class ConstantScoreQuery implements BuilderInterface { use ParametersTrait; + const USE_QUERY = 'query'; + const USE_FILTER = 'filter'; + /** * @var string */ @@ -29,16 +32,17 @@ class ConstantScoreQuery implements BuilderInterface /** * @var BuilderInterface */ - private $filterOrQuery; + private $query; /** - * @param BuilderInterface $filterOrQuery + * @param BuilderInterface $query * @param array $parameters + * @param string $dslType */ - public function __construct(BuilderInterface $filterOrQuery, array $parameters = []) + public function __construct(BuilderInterface $query, array $parameters = [], $dslType = self::USE_FILTER) { - $this->dslType = array_slice(explode('\\', get_class($filterOrQuery)), -2, 1)[0]; - $this->filterOrQuery = $filterOrQuery; + $this->dslType = $dslType; + $this->query = $query; $this->setParameters($parameters); } @@ -57,7 +61,7 @@ class ConstantScoreQuery implements BuilderInterface { $query = [ strtolower($this->dslType) => [ - $this->filterOrQuery->getType() => $this->filterOrQuery->toArray(), + $this->query->getType() => $this->query->toArray(), ], ]; diff --git a/Query/FunctionScoreQuery.php b/Query/FunctionScoreQuery.php index 7584eb8d9b2cc0fbdf2ae28deeee020d02ac7aee..f8f05412aac15dc49d900f19be9db86ca8998dc5 100644 --- a/Query/FunctionScoreQuery.php +++ b/Query/FunctionScoreQuery.php @@ -21,6 +21,9 @@ class FunctionScoreQuery implements BuilderInterface { use ParametersTrait; + const USE_QUERY = 'query'; + const USE_FILTER = 'filter'; + /** * @var string */ @@ -29,7 +32,7 @@ class FunctionScoreQuery implements BuilderInterface /** * @var BuilderInterface */ - private $filterOrQuery; + private $query; /** * @var array[] @@ -37,14 +40,19 @@ class FunctionScoreQuery implements BuilderInterface private $functions; /** - * @param BuilderInterface $filterOrQuery + * @param BuilderInterface $query * @param array $functions * @param array $parameters + * @param string $dslType */ - public function __construct(BuilderInterface $filterOrQuery, array $functions, array $parameters = []) - { - $this->dslType = array_slice(explode('\\', get_class($filterOrQuery)), -2, 1)[0]; - $this->filterOrQuery = $filterOrQuery; + public function __construct( + BuilderInterface $query, + array $functions, + array $parameters = [], + $dslType = self::USE_FILTER + ) { + $this->dslType = $dslType; + $this->query = $query; $this->functions = $functions; $this->setParameters($parameters); } @@ -64,7 +72,7 @@ class FunctionScoreQuery implements BuilderInterface { $query = [ strtolower($this->dslType) => [ - $this->filterOrQuery->getType() => $this->filterOrQuery->toArray(), + $this->query->getType() => $this->query->toArray(), ], 'functions' => [$this->functions], ]; diff --git a/Query/MatchQuery.php b/Query/MatchQuery.php index 7bc82d6bd75aa78c806fee68a6bfd53f9e9912ce..e6a0330257dc7e7414144527c558c5a1543c58e5 100644 --- a/Query/MatchQuery.php +++ b/Query/MatchQuery.php @@ -24,22 +24,22 @@ class MatchQuery implements BuilderInterface /** * @var string */ - private $query; + private $field; /** * @var string */ - private $field; + private $query; /** - * @param string $query * @param string $field + * @param string $query * @param array $parameters */ - public function __construct($query, $field, array $parameters = []) + public function __construct($field, $query, array $parameters = []) { - $this->query = $query; $this->field = $field; + $this->query = $query; $this->setParameters($parameters); } diff --git a/Query/MultiMatchQuery.php b/Query/MultiMatchQuery.php index 48695fdbfb1fa1f613fdaf4b756fe24fd0f8f5d4..d221b2691eb6bd1a808195396ddc84151432c765 100644 --- a/Query/MultiMatchQuery.php +++ b/Query/MultiMatchQuery.php @@ -19,9 +19,14 @@ use ONGR\ElasticsearchBundle\DSL\BuilderInterface; class MultiMatchQuery implements BuilderInterface { /** - * @var string + * @param array $fields + * @param string $query */ - private $query; + public function __construct(array $fields, $query) + { + $this->fields = $fields; + $this->query = $query; + } /** * @var array @@ -29,14 +34,9 @@ class MultiMatchQuery implements BuilderInterface private $fields = []; /** - * @param string $query - * @param array $fields + * @var string */ - public function __construct($query, array $fields) - { - $this->query = $query; - $this->fields = $fields; - } + private $query; /** * {@inheritdoc} @@ -52,8 +52,8 @@ class MultiMatchQuery implements BuilderInterface public function toArray() { return [ - 'query' => $this->query, 'fields' => $this->fields, + 'query' => $this->query, ]; } }