Skip to content

Commit 1002328

Browse files
committed
Fix filter dsl inconsistency
1 parent 955f968 commit 1002328

File tree

3 files changed

+35
-37
lines changed

3 files changed

+35
-37
lines changed

lib/Elastica/Filter/AbstractMulti.php

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

54
/**
@@ -21,7 +20,9 @@ abstract class AbstractMulti extends AbstractFilter
2120
*/
2221
public function __construct(array $filters = array())
2322
{
24-
$this->setFilters($filters);
23+
if (!empty($filters)) {
24+
$this->setFilters($filters);
25+
}
2526
}
2627

2728
/**

lib/Elastica/Filter/Type.php

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

54
/**

lib/Elastica/QueryBuilder/DSL/Filter.php

+32-34
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,9 @@ public function getType()
6262
*
6363
* @return BoolAnd
6464
*/
65-
public function bool_and(array $filters)
65+
public function bool_and(array $filters = array())
6666
{
67-
$and = new BoolAnd();
68-
$and->setFilters($filters);
69-
70-
return $and;
67+
return new BoolAnd($filters);
7168
}
7269

7370
/**
@@ -101,14 +98,14 @@ public function exists($field)
10198
*
10299
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-filter.html
103100
*
104-
* @param string $field
101+
* @param string $key
105102
* @param array $coordinates
106103
*
107104
* @return GeoBoundingBox
108105
*/
109-
public function geo_bounding_box($field, array $coordinates)
106+
public function geo_bounding_box($key, array $coordinates)
110107
{
111-
return new GeoBoundingBox($field, $coordinates);
108+
return new GeoBoundingBox($key, $coordinates);
112109
}
113110

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

212209
/**
@@ -219,7 +216,7 @@ public function geohash_cell($field, $location, $precision = -1, $neighbors = fa
219216
*
220217
* @return HasChild
221218
*/
222-
public function has_child($query, $type)
219+
public function has_child($query, $type = null)
223220
{
224221
return new HasChild($query, $type);
225222
}
@@ -249,7 +246,7 @@ public function has_parent($query, $type)
249246
*
250247
* @return Ids
251248
*/
252-
public function ids($type, array $ids)
249+
public function ids($type = null, array $ids = array())
253250
{
254251
return new Ids($type, $ids);
255252
}
@@ -304,7 +301,7 @@ public function match_all()
304301
*
305302
* @return Missing
306303
*/
307-
public function missing($field)
304+
public function missing($field = '')
308305
{
309306
return new Missing($field);
310307
}
@@ -340,11 +337,14 @@ public function bool_not(AbstractFilter $filter)
340337
*
341338
* @link http://www.elastic.co/guide/en/elasticsearch/reference/0.90/query-dsl-numeric-range-filter.html
342339
*
340+
* @param string $fieldName Field name
341+
* @param array $args Field arguments
342+
*
343343
* @return NumericRange
344344
*/
345-
public function numeric_range()
345+
public function numeric_range($fieldName = '', array $args = array())
346346
{
347-
return new NumericRange();
347+
return new NumericRange($fieldName, $args);
348348
}
349349

350350
/**
@@ -356,12 +356,9 @@ public function numeric_range()
356356
*
357357
* @return BoolOr
358358
*/
359-
public function bool_or($filters)
359+
public function bool_or(array $filters = array())
360360
{
361-
$or = new BoolOr();
362-
$or->setFilters($filters);
363-
364-
return $or;
361+
return new BoolOr($filters);
365362
}
366363

367364
/**
@@ -374,7 +371,7 @@ public function bool_or($filters)
374371
*
375372
* @return Prefix
376373
*/
377-
public function prefix($field, $prefix)
374+
public function prefix($field = '', $prefix = '')
378375
{
379376
return new Prefix($field, $prefix);
380377
}
@@ -384,11 +381,11 @@ public function prefix($field, $prefix)
384381
*
385382
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html
386383
*
387-
* @param AbstractQuery $query
384+
* @param array|AbstractQuery $query
388385
*
389386
* @return QueryFilter
390387
*/
391-
public function query(AbstractQuery $query)
388+
public function query($query = null)
392389
{
393390
return new QueryFilter($query);
394391
}
@@ -403,7 +400,7 @@ public function query(AbstractQuery $query)
403400
*
404401
* @return Range
405402
*/
406-
public function range($fieldName, array $args)
403+
public function range($fieldName = '', array $args = array())
407404
{
408405
return new Range($fieldName, $args);
409406
}
@@ -413,14 +410,15 @@ public function range($fieldName, array $args)
413410
*
414411
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-filter.html
415412
*
416-
* @param string $field
417-
* @param string $regexp
413+
* @param string $field Field name
414+
* @param string $regexp Regular expression
415+
* @param array $options Regular expression options
418416
*
419417
* @return Regexp
420418
*/
421-
public function regexp($field, $regexp)
419+
public function regexp($field = '', $regexp = '', $options = array())
422420
{
423-
return new Regexp($field, $regexp);
421+
return new Regexp($field, $regexp, $options);
424422
}
425423

426424
/**
@@ -432,7 +430,7 @@ public function regexp($field, $regexp)
432430
*
433431
* @return Script
434432
*/
435-
public function script($script)
433+
public function script($script = null)
436434
{
437435
return new Script($script);
438436
}
@@ -456,14 +454,14 @@ public function term(array $term = array())
456454
*
457455
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html
458456
*
459-
* @param string $field
457+
* @param string $key
460458
* @param array $terms
461459
*
462460
* @return Terms
463461
*/
464-
public function terms($field, array $terms)
462+
public function terms($key = '', array $terms = array())
465463
{
466-
return new Terms($field, $terms);
464+
return new Terms($key, $terms);
467465
}
468466

469467
/**
@@ -475,7 +473,7 @@ public function terms($field, array $terms)
475473
*
476474
* @return Type
477475
*/
478-
public function type($type)
476+
public function type($type = null)
479477
{
480478
return new Type($type);
481479
}

0 commit comments

Comments
 (0)