Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/2.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Query/BoolQuery.php
#	src/Query/FunctionScoreQuery.php
#	src/Query/LimitQuery.php
#	src/Query/MissingQuery.php
  • Loading branch information
Simonas Šerlinskas committed Jan 30, 2017
2 parents 6c93348 + a5d77e6 commit f3ba17d
Show file tree
Hide file tree
Showing 70 changed files with 2,710 additions and 1,922 deletions.
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# CHANGELOG

v2.x (2016-x)
v5.0.0 (2017-x)
---

- **[BC break]** Removed deprecated aggregation classes.
- **[BC break]** Removed deprecated query classes.

v2.2.1 (2017-01-26)
---
- Fixed function score for 2.x elastic.
- Fixed bug in nested and reverse nested aggregations. (#173)
- Fixed bool query key assign for some OS to avoid duplication.

v2.2.0 (2016-11.11)
---
- Added support for elasticsearch 5.0
Expand Down Expand Up @@ -67,3 +74,7 @@ v1.0.1 (2015-12-16)
- Fixed `function_score` query options handling [#35](https://github.com/ongr-io/ElasticsearchDSL/issues/35)
- Added Symfony 3 compatibility
- Added support for `timeout` and `terminate_after` options in Search endpoint [#34](https://github.com/ongr-io/ElasticsearchDSL/issues/34)

v1.0.0 (2015-09-14)
---
- First stable version, [more info here](https://github.com/ongr-io/ElasticsearchDSL/blob/v1.0.0/docs/index.md).
112 changes: 3 additions & 109 deletions src/Query/BoolQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,119 +11,13 @@

namespace ONGR\ElasticsearchDSL\Query;

use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;

/**
* Represents Elasticsearch "bool" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
*
* @deprecated Use the extended class instead. This class is left only for BC compatibility.
*/
class BoolQuery implements BuilderInterface
class BoolQuery extends \ONGR\ElasticsearchDSL\Query\Compound\BoolQuery
{
use ParametersTrait;

const MUST = 'must';
const MUST_NOT = 'must_not';
const SHOULD = 'should';
const FILTER = 'filter';

/**
* @var array
*/
private $container = [];

/**
* Constructor to prepare container.
*/
public function __construct()
{
$this->container = [];
}

/**
* Returns the query instances (by bool type).
*
* @param string|null $boolType
*
* @return array
*/
public function getQueries($boolType = null)
{
if ($boolType === null) {
$queries = [];

foreach ($this->container as $item) {
$queries = array_merge($queries, $item);
}

return $queries;
}

if (isset($this->container[$boolType])) {
return $this->container[$boolType];
}

return [];
}

/**
* Add BuilderInterface object to bool operator.
*
* @param BuilderInterface $query Query add to the bool.
* @param string $type Bool type. Example: must, must_not, should.
* @param string $key Key that indicates a builder id.
*
* @return string Key of added builder.
*
* @throws \UnexpectedValueException
*/
public function add(BuilderInterface $query, $type = self::MUST, $key = null)
{
if (!in_array($type, [self::MUST, self::MUST_NOT, self::SHOULD, self::FILTER])) {
throw new \UnexpectedValueException(sprintf('The bool operator %s is not supported', $type));
}

if (!$key) {
$key = bin2hex(random_bytes(30));
}

$this->container[$type][$key] = $query;

return $key;
}

/**
* {@inheritdoc}
*/
public function toArray()
{
if (count($this->container) === 1 && isset($this->container[self::MUST])
&& count($this->container[self::MUST]) === 1) {
$query = reset($this->container[self::MUST]);

return $query->toArray();
}

$output = [];

foreach ($this->container as $boolType => $builders) {
/** @var BuilderInterface $builder */
foreach ($builders as $builder) {
$output[$boolType][] = $builder->toArray();
}
}

$output = $this->processArray($output);

return [$this->getType() => $output];
}

/**
* {@inheritdoc}
*/
public function getType()
{
return 'bool';
}
}
54 changes: 3 additions & 51 deletions src/Query/BoostingQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,13 @@

namespace ONGR\ElasticsearchDSL\Query;

use ONGR\ElasticsearchDSL\BuilderInterface;

/**
* Represents Elasticsearch "boosting" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html
*
* @deprecated Use the extended class instead. This class is left only for BC compatibility.
*/
class BoostingQuery implements BuilderInterface
class BoostingQuery extends \ONGR\ElasticsearchDSL\Query\Compound\BoostingQuery
{
/**
* @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->toArray(),
'negative' => $this->negative->toArray(),
'negative_boost' => $this->negativeBoost,
];

return [$this->getType() => $query];
}
}
54 changes: 3 additions & 51 deletions src/Query/CommonTermsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,13 @@

namespace ONGR\ElasticsearchDSL\Query;

use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;

/**
* Represents Elasticsearch "common" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html
*
* @deprecated Use the extended class instead. This class is left only for BC compatibility.
*/
class CommonTermsQuery implements BuilderInterface
class CommonTermsQuery extends \ONGR\ElasticsearchDSL\Query\FullText\CommonTermsQuery
{
use ParametersTrait;

/**
* @var string
*/
private $field;

/**
* @var string
*/
private $query;

/**
* @param string $field
* @param string $query
* @param array $parameters
*/
public function __construct($field, $query, array $parameters = [])
{
$this->field = $field;
$this->query = $query;
$this->setParameters($parameters);
}

/**
* {@inheritdoc}
*/
public function getType()
{
return 'common';
}

/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [
'query' => $this->query,
];

$output = [
$this->field => $this->processArray($query),
];

return [$this->getType() => $output];
}
}
Loading

0 comments on commit f3ba17d

Please sign in to comment.