Skip to content

Commit 4dae780

Browse files
committed
Merge pull request #822 from ruflin/empty-bool-query-as-match-all
Fix empty bool query to act as match all query #817
2 parents cc60e8f + 59fca67 commit 4dae780

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

changes.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CHANGES
22

3+
2015-04-23
4+
- Fix empty bool query to act as match all query #817
5+
36
2015-04-15
47
- deleteByQuery() implemented in Elastica\Index
58

lib/Elastica/Query/Bool.php

+14
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,18 @@ public function setMinimumNumberShouldMatch($minimumNumberShouldMatch)
9090
{
9191
return $this->setParam('minimum_number_should_match', $minimumNumberShouldMatch);
9292
}
93+
94+
/**
95+
* Converts array to an object in case no queries are added
96+
*
97+
* @return array
98+
*/
99+
public function toArray()
100+
{
101+
if (empty($this->_params)) {
102+
$this->_params = new \stdClass();
103+
}
104+
return parent::toArray();
105+
}
106+
93107
}

test/lib/Elastica/Test/Query/BoolTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,25 @@ public function testSearch()
111111

112112
$this->assertEquals(0, $resultSet->count());
113113
}
114+
115+
public function testEmptyBoolQuery() {
116+
$index = $this->_createIndex();
117+
$type = new Type($index, 'test');
118+
119+
$docNumber = 3;
120+
for ($i = 0; $i < $docNumber; $i++) {
121+
$doc = new Document($i, array('email' => '[email protected]'));
122+
$type->addDocument($doc);
123+
}
124+
125+
$index->refresh();
126+
127+
$boolQuery = new Bool();
128+
129+
$resultSet = $type->search($boolQuery);
130+
131+
$this->assertEquals($resultSet->count(), $docNumber);
132+
133+
134+
}
114135
}

0 commit comments

Comments
 (0)