diff --git a/Query/Span/SpanFirstQuery.php b/Query/Span/SpanFirstQuery.php new file mode 100644 index 0000000000000000000000000000000000000000..66a9ff84657a64e560e5c1a2f125156df7aa8ea1 --- /dev/null +++ b/Query/Span/SpanFirstQuery.php @@ -0,0 +1,67 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\DSL\Query\Span; + +use ONGR\ElasticsearchBundle\DSL\ParametersTrait; + +/** + * Elasticsearch span first query. + */ +class SpanFirstQuery implements SpanQueryInterface +{ + use ParametersTrait; + + /** + * @var SpanQueryInterface + */ + private $query; + + /** + * @var int + */ + private $end; + + /** + * @param SpanQueryInterface $query + * @param int $end + * @param array $parameters + * + * @throws \LogicException + */ + public function __construct(SpanQueryInterface $query, $end, array $parameters = []) + { + $this->query = $query; + $this->end = $end; + $this->setParameters($parameters); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'span_first'; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + $query = []; + $query['match'] = [$this->query->getType() => $this->query->toArray()]; + $query['end'] = $this->end; + $output = $this->processArray($query); + + return $output; + } +} diff --git a/Query/Span/SpanMultiTermQuery.php b/Query/Span/SpanMultiTermQuery.php new file mode 100644 index 0000000000000000000000000000000000000000..ff47353b250e613047410ec1d1abcf48603e5d81 --- /dev/null +++ b/Query/Span/SpanMultiTermQuery.php @@ -0,0 +1,61 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\DSL\Query\Span; + +use ONGR\ElasticsearchBundle\DSL\BuilderInterface; +use ONGR\ElasticsearchBundle\DSL\ParametersTrait; + +/** + * Elasticsearch span multi term query. + */ +class SpanMultiTermQuery implements SpanQueryInterface +{ + use ParametersTrait; + + /** + * @var BuilderInterface + */ + private $query; + + /** + * Accepts one of fuzzy, prefix, term range, wildcard, regexp query. + * + * @param BuilderInterface $query + * @param array $parameters + */ + public function __construct(BuilderInterface $query, array $parameters = []) + { + $this->query = $query; + $this->setParameters($parameters); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'span_multi'; + } + + /** + * {@inheritdoc} + * + * @throws \InvalidArgumentException + */ + public function toArray() + { + $query['match'] = [$this->query->getType() => $this->query->toArray()]; + $output = $this->processArray($query); + + return $output; + } +} diff --git a/Query/Span/SpanNearQuery.php b/Query/Span/SpanNearQuery.php new file mode 100644 index 0000000000000000000000000000000000000000..48047645b4540a768d754c5ddc569708b903e93f --- /dev/null +++ b/Query/Span/SpanNearQuery.php @@ -0,0 +1,70 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\DSL\Query\Span; + +use ONGR\ElasticsearchBundle\DSL\ParametersTrait; + +/** + * Elasticsearch span near query. + */ +class SpanNearQuery implements SpanQueryInterface +{ + use ParametersTrait; + + /** + * @var int + */ + private $slop; + + /** + * @var SpanQueryInterface[] + */ + private $queries = []; + + /** + * @param int $slop + * @param SpanQueryInterface[] $queries + * @param array $parameters + * + * @throws \LogicException + */ + public function __construct($slop, array $queries = [], array $parameters = []) + { + $this->slop = $slop; + $this->queries = $queries; + $this->setParameters($parameters); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'span_near'; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + $query = []; + foreach ($this->queries as $type) { + $data = [$type->getType() => $type->toArray()]; + $query['clauses'][] = $data; + } + $query['slop'] = $this->slop; + $output = $this->processArray($query); + + return $output; + } +} diff --git a/Query/Span/SpanNotQuery.php b/Query/Span/SpanNotQuery.php new file mode 100644 index 0000000000000000000000000000000000000000..9ce85c07b951c09f2f8d4f17867890c4505e9750 --- /dev/null +++ b/Query/Span/SpanNotQuery.php @@ -0,0 +1,65 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\DSL\Query\Span; + +use ONGR\ElasticsearchBundle\DSL\ParametersTrait; + +/** + * Elasticsearch Span not query. + */ +class SpanNotQuery implements SpanQueryInterface +{ + use ParametersTrait; + + /** + * @var SpanQueryInterface + */ + private $include; + + /** + * @var SpanQueryInterface + */ + private $exclude; + + /** + * @param SpanQueryInterface $include + * @param SpanQueryInterface $exclude + * @param array $parameters + */ + public function __construct(SpanQueryInterface $include, SpanQueryInterface $exclude, array $parameters = []) + { + $this->include = $include; + $this->exclude = $exclude; + $this->setParameters($parameters); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'span_not'; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + $query = [ + 'include' => [$this->include->getType() => $this->include->toArray()], + 'exclude' => [$this->exclude->getType() => $this->exclude->toArray()], + ]; + + return $query; + } +} diff --git a/Query/Span/SpanOrQuery.php b/Query/Span/SpanOrQuery.php new file mode 100644 index 0000000000000000000000000000000000000000..a18df02cdd078b1ac15d790a69e2898f5506d7fb --- /dev/null +++ b/Query/Span/SpanOrQuery.php @@ -0,0 +1,62 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\DSL\Query\Span; + +use ONGR\ElasticsearchBundle\DSL\ParametersTrait; + +/** + * Elasticsearch span or query. + */ +class SpanOrQuery implements SpanQueryInterface +{ + use ParametersTrait; + + /** + * @var SpanQueryInterface[] + */ + private $queries = []; + + /** + * @param SpanQueryInterface[] $queries + * @param array $parameters + */ + public function __construct(array $queries = [], array $parameters = []) + { + foreach ($queries as $query) { + $this->queries[] = $query; + } + $this->setParameters($parameters); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'span_or'; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + $query = []; + foreach ($this->queries as $type) { + $data = [$type->getType() => $type->toArray()]; + $query['clauses'][] = $data; + } + $output = $this->processArray($query); + + return $output; + } +} diff --git a/Query/Span/SpanQueryInterface.php b/Query/Span/SpanQueryInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..45fdea9589f6f0b2c05c67fb456662d66e5642da --- /dev/null +++ b/Query/Span/SpanQueryInterface.php @@ -0,0 +1,21 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\DSL\Query\Span; + +use ONGR\ElasticsearchBundle\DSL\BuilderInterface; + +/** + * Interface SpanQueryInterface to recognise span queries. + */ +interface SpanQueryInterface extends BuilderInterface +{ +} diff --git a/Query/Span/SpanTermQuery.php b/Query/Span/SpanTermQuery.php new file mode 100644 index 0000000000000000000000000000000000000000..7ccde21ca102e51255ea5abe9c903d2467238959 --- /dev/null +++ b/Query/Span/SpanTermQuery.php @@ -0,0 +1,28 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\DSL\Query\Span; + +use ONGR\ElasticsearchBundle\DSL\Query\TermQuery; + +/** + * Elasticsearch span_term query class. + */ +class SpanTermQuery extends TermQuery implements SpanQueryInterface +{ + /** + * {@inheritdoc} + */ + public function getType() + { + return 'span_term'; + } +} diff --git a/Query/SpanTermQuery.php b/Query/SpanTermQuery.php deleted file mode 100644 index d88d460cc6ddfb7e127870c2ce5734897235bac9..0000000000000000000000000000000000000000 --- a/Query/SpanTermQuery.php +++ /dev/null @@ -1,69 +0,0 @@ -<?php - -/* - * This file is part of the ONGR package. - * - * (c) NFQ Technologies UAB <info@nfq.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ElasticsearchBundle\DSL\Query; - -use ONGR\ElasticsearchBundle\DSL\BuilderInterface; -use ONGR\ElasticsearchBundle\DSL\ParametersTrait; - -/** - * Elasticsearch span_term query class. - */ -class SpanTermQuery implements BuilderInterface -{ - use ParametersTrait; - - /** - * @var string - */ - private $field; - - /** - * @var string - */ - private $value; - - /** - * @param string $field - * @param string $value - * @param array $parameters - */ - public function __construct($field, $value, array $parameters = []) - { - $this->field = $field; - $this->value = $value; - $this->setParameters($parameters); - } - - /** - * {@inheritdoc} - */ - public function getType() - { - return 'span_term'; - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $query = [ - 'value' => $this->value, - ]; - - $output = [ - $this->field => $this->processArray($query), - ]; - - return $output; - } -}