Skip to content

Commit 08be155

Browse files
committed
Merge pull request #935 from ewgRa/fix-filters-keys
fix empty string is not anonymous filter
2 parents c1b1fec + 3fbfa6b commit 08be155

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
All notable changes to this project will be documented in this file based on the [Keep a Changelog](http://keepachangelog.com/) Standard. This project adheres to [Semantic Versioning](http://semver.org/).
33

44
## [Unreleased](https://github.com/ruflin/Elastica/compare/2.3.0...HEAD)
5+
- Filters aggregation: empty name is named bucket #935
56

67
### Backward Compatibility Breaks
78

89
### Bugfixes
10+
- Filters aggregation: empty name is named bucket #935
911

1012
### Added
1113

lib/Elastica/Aggregation/Filters.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Filters extends AbstractAggregation
2020
*
2121
* @return $this
2222
*/
23-
public function addFilter(AbstractFilter $filter, $name = '')
23+
public function addFilter(AbstractFilter $filter, $name = null)
2424
{
2525
$filterArray = array();
2626

@@ -45,7 +45,7 @@ public function toArray()
4545
// Detect between anonymous filters and named ones
4646
$key = key($filter);
4747

48-
if (is_string($key) && !empty($key)) {
48+
if (is_string($key)) {
4949
$array['filters']['filters'][$key] = current($filter)->toArray();
5050
} else {
5151
$array['filters']['filters'][] = current($filter)->toArray();

test/lib/Elastica/Test/Aggregation/FiltersTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public function testToArrayUsingNamedFilters()
3434
$expected = array(
3535
'filters' => array(
3636
'filters' => array(
37+
'' => array(
38+
'term' => array('color' => ''),
39+
),
40+
'0' => array(
41+
'term' => array('color' => '0'),
42+
),
3743
'blue' => array(
3844
'term' => array('color' => 'blue'),
3945
),
@@ -48,6 +54,8 @@ public function testToArrayUsingNamedFilters()
4854
);
4955

5056
$agg = new Filters('by_color');
57+
$agg->addFilter(new Term(array('color' => '')), '');
58+
$agg->addFilter(new Term(array('color' => '0')), '0');
5159
$agg->addFilter(new Term(array('color' => 'blue')), 'blue');
5260
$agg->addFilter(new Term(array('color' => 'red')), 'red');
5361

0 commit comments

Comments
 (0)