diff --git a/Query/BoostingQuery.php b/Query/BoostingQuery.php new file mode 100644 index 0000000000000000000000000000000000000000..2dcf23baeb99a094a0c977f83b798e3d4353c040 --- /dev/null +++ b/Query/BoostingQuery.php @@ -0,0 +1,69 @@ +<?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; + +/** + * Elasticsearch boosting query class. + */ +class BoostingQuery implements BuilderInterface +{ + /** + * @var BuilderInterface + */ + private $positive; + + /** + * @var BuilderInterface + */ + private $negative; + + /** + * @var int|float + */ + private $negativeBoost; + + /** + * @param BuilderInterface $positive + * @param BuilderInterface $negative + * @param int|float $negativeBoost + */ + public function __construct(BuilderInterface $positive, BuilderInterface $negative, $negativeBoost) + { + $this->positive = $positive; + $this->negative = $negative; + $this->negativeBoost = $negativeBoost; + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'boosting'; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + $query = [ + 'positive' => [$this->positive->getType() => $this->positive->toArray()], + 'negative' => [$this->negative->getType() => $this->negative->toArray()], + 'negative_boost' => $this->negativeBoost, + ]; + + return $query; + } +} diff --git a/Query/DisMaxQuery.php b/Query/DisMaxQuery.php new file mode 100644 index 0000000000000000000000000000000000000000..f457f7d45ac5d534e49abf0301d92b3ba45351cc --- /dev/null +++ b/Query/DisMaxQuery.php @@ -0,0 +1,69 @@ +<?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 dis max query class. + */ +class DisMaxQuery implements BuilderInterface +{ + use ParametersTrait; + + /** + * @var BuilderInterface[] + */ + private $queries = []; + + /** + * Initializes Dis Max query. + * + * @param BuilderInterface[] $queries + * @param array $parameters + * + * @throws \InvalidArgumentException + */ + public function __construct(array $queries = [], array $parameters = []) + { + foreach ($queries as $query) { + if ($query instanceof BuilderInterface) { + $this->queries[] = $query; + } else { + throw new \InvalidArgumentException('Arguments must be instance of BuilderInterface'); + } + } + $this->setParameters($parameters); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'dis_max'; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + foreach ($this->queries as $type) { + $query['queries'][] = [$type->getType() => $type->toArray()]; + } + $output = $this->processArray($query); + + return $output; + } +} diff --git a/Query/PrefixQuery.php b/Query/PrefixQuery.php new file mode 100644 index 0000000000000000000000000000000000000000..62b1bd6e8a59904da5ba447927927a26f3dd2656 --- /dev/null +++ b/Query/PrefixQuery.php @@ -0,0 +1,69 @@ +<?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; + +/** + * Represents Elasticsearch "prefix" query. + */ +class PrefixQuery implements BuilderInterface +{ + use ParametersTrait; + + /** + * @var string + */ + private $field; + + /** + * @var string + */ + private $value; + + /** + * @param string $field Field name. + * @param string $value Value. + * @param array $parameters Optional parameters. + */ + public function __construct($field, $value, array $parameters = []) + { + $this->field = $field; + $this->value = $value; + $this->setParameters($parameters); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'prefix'; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + $query = [ + 'value' => $this->value, + ]; + + $output = [ + $this->field => $this->processArray($query), + ]; + + return $output; + } +}