Skip to content

Commit

Permalink
Update QueryBuilder\DSL tests
Browse files Browse the repository at this point in the history
  • Loading branch information
im-denisenko committed Jun 15, 2015
1 parent 97b9c66 commit 11900d8
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 305 deletions.
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
9 changes: 9 additions & 0 deletions lib/Elastica/Filter/AbstractMulti.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Elastica\Filter;

/**
Expand All @@ -15,6 +16,14 @@ abstract class AbstractMulti extends AbstractFilter
*/
protected $_filters = array();

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

/**
* Add filter.
*
Expand Down
9 changes: 5 additions & 4 deletions lib/Elastica/Filter/Type.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Elastica\Filter;

/**
Expand All @@ -20,12 +21,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
26 changes: 9 additions & 17 deletions lib/Elastica/QueryBuilder/DSL/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,8 @@ public function percentiles($name, $field = null)
* percentile ranks aggregation.
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-rank-aggregation.html
*
* @param string $name
*/
public function percentile_ranks($name)
public function percentile_ranks()
{
throw new NotImplementedException();
}
Expand All @@ -194,10 +192,8 @@ public function cardinality($name)
* geo bounds aggregation.
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geobounds-aggregation.html
*
* @param string $name
*/
public function geo_bounds($name)
public function geo_bounds()
{
throw new NotImplementedException();
}
Expand Down Expand Up @@ -258,12 +254,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,23 +308,22 @@ 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);
return new ReverseNested($name, $path);
}

/**
* children aggregation.
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html
*
* @param string $name
*/
public function children($name)
public function children()
{
throw new NotImplementedException();
}
Expand Down
71 changes: 35 additions & 36 deletions lib/Elastica/QueryBuilder/DSL/Filter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Elastica\QueryBuilder\DSL;

use Elastica\Filter\AbstractFilter;
Expand Down Expand Up @@ -62,12 +63,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 +99,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,29 +195,29 @@ 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);
}

/**
* has child filter.
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html
*
* @param AbstractQuery|AbstractFilter $query
* @param string $type
* @param string|\Elastica\Query|\Elastica\Filter\AbstractFilter $query Query string or a Elastica\Query object or a filter
* @param string|\Elastica\Type $type Child document type
*
* @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 +247,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 +302,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 +338,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 +357,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 +372,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 +382,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|\Elastica\Query\AbstractQuery $query
*
* @return QueryFilter
*/
public function query(AbstractQuery $query)
public function query($query = null)
{
return new QueryFilter($query);
}
Expand All @@ -403,7 +401,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 +411,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 +431,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 +455,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 +474,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

0 comments on commit 11900d8

Please sign in to comment.