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

Added missing DSL queries

parent 67e1a417
No related branches found
No related tags found
No related merge requests found
<?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;
}
}
<?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;
}
}
<?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;
}
}
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