Skip to content

Commit 11900d8

Browse files
committed
Update QueryBuilder\DSL tests
1 parent 97b9c66 commit 11900d8

File tree

11 files changed

+329
-305
lines changed

11 files changed

+329
-305
lines changed

lib/Elastica/Aggregation/Filter.php

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010
*/
1111
class Filter extends AbstractAggregation
1212
{
13+
/**
14+
* @param string $name
15+
* @param AbstractFilter $filter
16+
*/
17+
public function __construct($name, AbstractFilter $filter = null)
18+
{
19+
parent::__construct($name);
20+
21+
if ($filter !== null) {
22+
$this->setFilter($filter);
23+
}
24+
}
25+
1326
/**
1427
* Set the filter for this aggregation.
1528
*

lib/Elastica/Filter/AbstractMulti.php

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Elastica\Filter;
34

45
/**
@@ -15,6 +16,14 @@ abstract class AbstractMulti extends AbstractFilter
1516
*/
1617
protected $_filters = array();
1718

19+
/**
20+
* @param \Elastica\Filter\AbstractFilter $filters
21+
*/
22+
public function __construct(array $filters = array())
23+
{
24+
$this->setFilters($filters);
25+
}
26+
1827
/**
1928
* Add filter.
2029
*

lib/Elastica/Filter/Type.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Elastica\Filter;
34

45
/**
@@ -20,12 +21,12 @@ class Type extends AbstractFilter
2021
/**
2122
* Construct Type Filter.
2223
*
23-
* @param string $typeName Type name
24+
* @param string $type Type name
2425
*/
25-
public function __construct($typeName = null)
26+
public function __construct($type = null)
2627
{
27-
if ($typeName) {
28-
$this->setType($typeName);
28+
if ($type) {
29+
$this->setType($type);
2930
}
3031
}
3132

lib/Elastica/QueryBuilder/DSL/Aggregation.php

+9-17
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,8 @@ public function percentiles($name, $field = null)
168168
* percentile ranks aggregation.
169169
*
170170
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-rank-aggregation.html
171-
*
172-
* @param string $name
173171
*/
174-
public function percentile_ranks($name)
172+
public function percentile_ranks()
175173
{
176174
throw new NotImplementedException();
177175
}
@@ -194,10 +192,8 @@ public function cardinality($name)
194192
* geo bounds aggregation.
195193
*
196194
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geobounds-aggregation.html
197-
*
198-
* @param string $name
199195
*/
200-
public function geo_bounds($name)
196+
public function geo_bounds()
201197
{
202198
throw new NotImplementedException();
203199
}
@@ -258,12 +254,9 @@ public function global_agg($name)
258254
*
259255
* @return FilterAggregation
260256
*/
261-
public function filter($name, AbstractFilter $filter)
257+
public function filter($name, AbstractFilter $filter = null)
262258
{
263-
$filterAgg = new FilterAggregation($name);
264-
$filterAgg->setFilter($filter);
265-
266-
return $filterAgg;
259+
return new FilterAggregation($name, $filter);
267260
}
268261

269262
/**
@@ -315,23 +308,22 @@ public function nested($name, $path)
315308
*
316309
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html
317310
*
318-
* @param string $name
311+
* @param string $name The name of this aggregation
312+
* @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document.
319313
*
320314
* @return ReverseNested
321315
*/
322-
public function reverse_nested($name)
316+
public function reverse_nested($name, $path = null)
323317
{
324-
return new ReverseNested($name);
318+
return new ReverseNested($name, $path);
325319
}
326320

327321
/**
328322
* children aggregation.
329323
*
330324
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html
331-
*
332-
* @param string $name
333325
*/
334-
public function children($name)
326+
public function children()
335327
{
336328
throw new NotImplementedException();
337329
}

lib/Elastica/QueryBuilder/DSL/Filter.php

+35-36
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Elastica\QueryBuilder\DSL;
34

45
use Elastica\Filter\AbstractFilter;
@@ -62,12 +63,9 @@ public function getType()
6263
*
6364
* @return BoolAnd
6465
*/
65-
public function bool_and(array $filters)
66+
public function bool_and(array $filters = array())
6667
{
67-
$and = new BoolAnd();
68-
$and->setFilters($filters);
69-
70-
return $and;
68+
return new BoolAnd($filters);
7169
}
7270

7371
/**
@@ -101,14 +99,14 @@ public function exists($field)
10199
*
102100
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-filter.html
103101
*
104-
* @param string $field
102+
* @param string $key
105103
* @param array $coordinates
106104
*
107105
* @return GeoBoundingBox
108106
*/
109-
public function geo_bounding_box($field, array $coordinates)
107+
public function geo_bounding_box($key, array $coordinates)
110108
{
111-
return new GeoBoundingBox($field, $coordinates);
109+
return new GeoBoundingBox($key, $coordinates);
112110
}
113111

114112
/**
@@ -197,29 +195,29 @@ public function geo_shape_pre_indexed($path, $indexedId, $indexedType, $indexedI
197195
*
198196
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geohash-cell-filter.html
199197
*
200-
* @param string $field The field on which to filter
198+
* @param string $key The field on which to filter
201199
* @param array|string $location Location as coordinates array or geohash string ['lat' => 40.3, 'lon' => 45.2]
202200
* @param int|string $precision length of geohash prefix or distance (3, or "50m")
203201
* @param bool $neighbors If true, filters cells next to the given cell.
204202
*
205203
* @return GeohashCell
206204
*/
207-
public function geohash_cell($field, $location, $precision = -1, $neighbors = false)
205+
public function geohash_cell($key, $location, $precision = -1, $neighbors = false)
208206
{
209-
return new GeohashCell($field, $location, $precision, $neighbors);
207+
return new GeohashCell($key, $location, $precision, $neighbors);
210208
}
211209

212210
/**
213211
* has child filter.
214212
*
215213
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html
216214
*
217-
* @param AbstractQuery|AbstractFilter $query
218-
* @param string $type
215+
* @param string|\Elastica\Query|\Elastica\Filter\AbstractFilter $query Query string or a Elastica\Query object or a filter
216+
* @param string|\Elastica\Type $type Child document type
219217
*
220218
* @return HasChild
221219
*/
222-
public function has_child($query, $type)
220+
public function has_child($query, $type = null)
223221
{
224222
return new HasChild($query, $type);
225223
}
@@ -249,7 +247,7 @@ public function has_parent($query, $type)
249247
*
250248
* @return Ids
251249
*/
252-
public function ids($type, array $ids)
250+
public function ids($type = null, array $ids = array())
253251
{
254252
return new Ids($type, $ids);
255253
}
@@ -304,7 +302,7 @@ public function match_all()
304302
*
305303
* @return Missing
306304
*/
307-
public function missing($field)
305+
public function missing($field = '')
308306
{
309307
return new Missing($field);
310308
}
@@ -340,11 +338,14 @@ public function bool_not(AbstractFilter $filter)
340338
*
341339
* @link http://www.elastic.co/guide/en/elasticsearch/reference/0.90/query-dsl-numeric-range-filter.html
342340
*
341+
* @param string $fieldName Field name
342+
* @param array $args Field arguments
343+
*
343344
* @return NumericRange
344345
*/
345-
public function numeric_range()
346+
public function numeric_range($fieldName = '', array $args = array())
346347
{
347-
return new NumericRange();
348+
return new NumericRange($fieldName, $args);
348349
}
349350

350351
/**
@@ -356,12 +357,9 @@ public function numeric_range()
356357
*
357358
* @return BoolOr
358359
*/
359-
public function bool_or($filters)
360+
public function bool_or(array $filters = array())
360361
{
361-
$or = new BoolOr();
362-
$or->setFilters($filters);
363-
364-
return $or;
362+
return new BoolOr($filters);
365363
}
366364

367365
/**
@@ -374,7 +372,7 @@ public function bool_or($filters)
374372
*
375373
* @return Prefix
376374
*/
377-
public function prefix($field, $prefix)
375+
public function prefix($field = '', $prefix = '')
378376
{
379377
return new Prefix($field, $prefix);
380378
}
@@ -384,11 +382,11 @@ public function prefix($field, $prefix)
384382
*
385383
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html
386384
*
387-
* @param AbstractQuery $query
385+
* @param array|\Elastica\Query\AbstractQuery $query
388386
*
389387
* @return QueryFilter
390388
*/
391-
public function query(AbstractQuery $query)
389+
public function query($query = null)
392390
{
393391
return new QueryFilter($query);
394392
}
@@ -403,7 +401,7 @@ public function query(AbstractQuery $query)
403401
*
404402
* @return Range
405403
*/
406-
public function range($fieldName, array $args)
404+
public function range($fieldName = '', array $args = array())
407405
{
408406
return new Range($fieldName, $args);
409407
}
@@ -413,14 +411,15 @@ public function range($fieldName, array $args)
413411
*
414412
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-filter.html
415413
*
416-
* @param string $field
417-
* @param string $regexp
414+
* @param string $field Field name
415+
* @param string $regexp Regular expression
416+
* @param array $options Regular expression options
418417
*
419418
* @return Regexp
420419
*/
421-
public function regexp($field, $regexp)
420+
public function regexp($field = '', $regexp = '', $options = array())
422421
{
423-
return new Regexp($field, $regexp);
422+
return new Regexp($field, $regexp, $options);
424423
}
425424

426425
/**
@@ -432,7 +431,7 @@ public function regexp($field, $regexp)
432431
*
433432
* @return Script
434433
*/
435-
public function script($script)
434+
public function script($script = null)
436435
{
437436
return new Script($script);
438437
}
@@ -456,14 +455,14 @@ public function term(array $term = array())
456455
*
457456
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html
458457
*
459-
* @param string $field
458+
* @param string $key
460459
* @param array $terms
461460
*
462461
* @return Terms
463462
*/
464-
public function terms($field, array $terms)
463+
public function terms($key = '', array $terms = array())
465464
{
466-
return new Terms($field, $terms);
465+
return new Terms($key, $terms);
467466
}
468467

469468
/**
@@ -475,7 +474,7 @@ public function terms($field, array $terms)
475474
*
476475
* @return Type
477476
*/
478-
public function type($type)
477+
public function type($type = null)
479478
{
480479
return new Type($type);
481480
}

0 commit comments

Comments
 (0)