Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryBuilder methods should have same signatures as corresponding constructors #878

Merged
merged 10 commits into from
Jun 21, 2015
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ All notable changes to this project will be documented in this file based on the
### Improvements
- `CallbackStrategy` now will accept any `callable` as callback, not only instance of `Closure`. [#871](https://github.com/ruflin/Elastica/pull/871)
- `StrategyFactory` now will try to find predefined strategy before looking to global namespace. [#877](https://github.com/ruflin/Elastica/pull/877)

- Methods of classes in `QueryBuilder\DSL` namespace now have exact same signatures as corresponding constructors. [#878](https://github.com/ruflin/Elastica/pull/878)
- Constructor of `Aggregation\Filter` now accepts filter as second parameter [#878](https://github.com/ruflin/Elastica/pull/878)
- Constructor of `Filter\AbstractMulti` (`BoolAnd`, `BooldOr`) now accepts array of filters as parameter [#878](https://github.com/ruflin/Elastica/pull/878)
- Constructor of `Query\Match` now accepts arguments [#878](https://github.com/ruflin/Elastica/pull/878)

## [2.1.0](https://github.com/ruflin/Elastica/releases/tag/2.1.0) - 2015-06-01

Expand Down
13 changes: 13 additions & 0 deletions lib/Elastica/Aggregation/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
*/
class Filter extends AbstractAggregation
{
/**
* @param string $name
* @param AbstractFilter $filter
*/
public function __construct($name, AbstractFilter $filter = null)
{
parent::__construct($name);

if ($filter !== null) {
$this->setFilter($filter);
}
}

/**
* Set the filter for this aggregation.
*
Expand Down
10 changes: 10 additions & 0 deletions lib/Elastica/Filter/AbstractMulti.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ abstract class AbstractMulti extends AbstractFilter
*/
protected $_filters = array();

/**
* @param \Elastica\Filter\AbstractFilter $filters
*/
public function __construct(array $filters = array())
{
if (!empty($filters)) {
$this->setFilters($filters);
}
}

/**
* Add filter.
*
Expand Down
8 changes: 4 additions & 4 deletions lib/Elastica/Filter/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class Type extends AbstractFilter
/**
* Construct Type Filter.
*
* @param string $typeName Type name
* @param string $type Type name
*/
public function __construct($typeName = null)
public function __construct($type = null)
{
if ($typeName) {
$this->setType($typeName);
if ($type) {
$this->setType($type);
}
}

Expand Down
11 changes: 11 additions & 0 deletions lib/Elastica/Query/Match.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ class Match extends AbstractQuery
const ZERO_TERM_NONE = 'none';
const ZERO_TERM_ALL = 'all';

/**
* @param string $field
* @param mixed $values
*/
public function __construct($field = null, $values = null)
{
if ($field !== null && $values !== null) {
$this->setParam($field, $values);
}
}

/**
* Sets a param for the message array.
*
Expand Down
12 changes: 5 additions & 7 deletions lib/Elastica/QueryBuilder/DSL/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,9 @@ public function global_agg($name)
*
* @return FilterAggregation
*/
public function filter($name, AbstractFilter $filter)
public function filter($name, AbstractFilter $filter = null)
{
$filterAgg = new FilterAggregation($name);
$filterAgg->setFilter($filter);

return $filterAgg;
return new FilterAggregation($name, $filter);
}

/**
Expand Down Expand Up @@ -315,11 +312,12 @@ public function nested($name, $path)
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html
*
* @param string $name
* @param string $name The name of this aggregation
* @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document.
*
* @return ReverseNested
*/
public function reverse_nested($name)
public function reverse_nested($name, $path = null)
{
return new ReverseNested($name);
}
Expand Down
66 changes: 32 additions & 34 deletions lib/Elastica/QueryBuilder/DSL/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ public function getType()
*
* @return BoolAnd
*/
public function bool_and(array $filters)
public function bool_and(array $filters = array())
{
$and = new BoolAnd();
$and->setFilters($filters);

return $and;
return new BoolAnd($filters);
}

/**
Expand Down Expand Up @@ -101,14 +98,14 @@ public function exists($field)
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-filter.html
*
* @param string $field
* @param string $key
* @param array $coordinates
*
* @return GeoBoundingBox
*/
public function geo_bounding_box($field, array $coordinates)
public function geo_bounding_box($key, array $coordinates)
{
return new GeoBoundingBox($field, $coordinates);
return new GeoBoundingBox($key, $coordinates);
}

/**
Expand Down Expand Up @@ -197,16 +194,16 @@ public function geo_shape_pre_indexed($path, $indexedId, $indexedType, $indexedI
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geohash-cell-filter.html
*
* @param string $field The field on which to filter
* @param string $key The field on which to filter
* @param array|string $location Location as coordinates array or geohash string ['lat' => 40.3, 'lon' => 45.2]
* @param int|string $precision length of geohash prefix or distance (3, or "50m")
* @param bool $neighbors If true, filters cells next to the given cell.
*
* @return GeohashCell
*/
public function geohash_cell($field, $location, $precision = -1, $neighbors = false)
public function geohash_cell($key, $location, $precision = -1, $neighbors = false)
{
return new GeohashCell($field, $location, $precision, $neighbors);
return new GeohashCell($key, $location, $precision, $neighbors);
}

/**
Expand All @@ -219,7 +216,7 @@ public function geohash_cell($field, $location, $precision = -1, $neighbors = fa
*
* @return HasChild
*/
public function has_child($query, $type)
public function has_child($query, $type = null)
{
return new HasChild($query, $type);
}
Expand Down Expand Up @@ -249,7 +246,7 @@ public function has_parent($query, $type)
*
* @return Ids
*/
public function ids($type, array $ids)
public function ids($type = null, array $ids = array())
{
return new Ids($type, $ids);
}
Expand Down Expand Up @@ -304,7 +301,7 @@ public function match_all()
*
* @return Missing
*/
public function missing($field)
public function missing($field = '')
{
return new Missing($field);
}
Expand Down Expand Up @@ -340,11 +337,14 @@ public function bool_not(AbstractFilter $filter)
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/0.90/query-dsl-numeric-range-filter.html
*
* @param string $fieldName Field name
* @param array $args Field arguments
*
* @return NumericRange
*/
public function numeric_range()
public function numeric_range($fieldName = '', array $args = array())
{
return new NumericRange();
return new NumericRange($fieldName, $args);
}

/**
Expand All @@ -356,12 +356,9 @@ public function numeric_range()
*
* @return BoolOr
*/
public function bool_or($filters)
public function bool_or(array $filters = array())
{
$or = new BoolOr();
$or->setFilters($filters);

return $or;
return new BoolOr($filters);
}

/**
Expand All @@ -374,7 +371,7 @@ public function bool_or($filters)
*
* @return Prefix
*/
public function prefix($field, $prefix)
public function prefix($field = '', $prefix = '')
{
return new Prefix($field, $prefix);
}
Expand All @@ -384,11 +381,11 @@ public function prefix($field, $prefix)
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html
*
* @param AbstractQuery $query
* @param array|AbstractQuery $query
*
* @return QueryFilter
*/
public function query(AbstractQuery $query)
public function query($query = null)
{
return new QueryFilter($query);
}
Expand All @@ -403,7 +400,7 @@ public function query(AbstractQuery $query)
*
* @return Range
*/
public function range($fieldName, array $args)
public function range($fieldName = '', array $args = array())
{
return new Range($fieldName, $args);
}
Expand All @@ -413,14 +410,15 @@ public function range($fieldName, array $args)
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-filter.html
*
* @param string $field
* @param string $regexp
* @param string $field Field name
* @param string $regexp Regular expression
* @param array $options Regular expression options
*
* @return Regexp
*/
public function regexp($field, $regexp)
public function regexp($field = '', $regexp = '', $options = array())
{
return new Regexp($field, $regexp);
return new Regexp($field, $regexp, $options);
}

/**
Expand All @@ -432,7 +430,7 @@ public function regexp($field, $regexp)
*
* @return Script
*/
public function script($script)
public function script($script = null)
{
return new Script($script);
}
Expand All @@ -456,14 +454,14 @@ public function term(array $term = array())
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html
*
* @param string $field
* @param string $key
* @param array $terms
*
* @return Terms
*/
public function terms($field, array $terms)
public function terms($key = '', array $terms = array())
{
return new Terms($field, $terms);
return new Terms($key, $terms);
}

/**
Expand All @@ -475,7 +473,7 @@ public function terms($field, array $terms)
*
* @return Type
*/
public function type($type)
public function type($type = null)
{
return new Type($type);
}
Expand Down
Loading