Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix raw post_filter #1950

Merged
merged 4 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed `Elastica\Connection\StrategyInterface` instance checks [#1921](https://github.com/ruflin/Elastica/pull/1921)
* Fixed various PHPDoc annotations [#1922](https://github.com/ruflin/Elastica/pull/1922)
* Fixed numeric index names are returned as `int` in `Elastica\Status::getIndexNames()` [#1928](https://github.com/ruflin/Elastica/pull/1928)
* Fixed using raw array in `post_filter` [#1950](https://github.com/ruflin/Elastica/pull/1950)
### Security

## [7.1.0](https://github.com/ruflin/Elastica/compare/7.0.0...7.1.0)
Expand Down
2 changes: 1 addition & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function toArray(): array
$this->setQuery(new MatchAll());
}

if (isset($this->_params['post_filter']) && 0 === \count(($this->_params['post_filter'])->toArray())) {
if (isset($this->_params['post_filter']) && 0 === \count($this->_params['post_filter'])) {
unset($this->_params['post_filter']);
}

Expand Down
26 changes: 26 additions & 0 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,32 @@ public function testSetPostFilterToArrayCast(): void
$this->assertEquals($query->toArray(), $anotherQuery->toArray());
}

/**
* @group unit
*/
public function testRawPostFilter(): void
{
$query = (new Query())
->setQuery(new Term(['field' => 'value']))
->setParam('post_filter', [
'term' => ['field' => 'value'],
])
;

$this->assertSame([
'query' => [
'term' => [
'field' => 'value',
],
],
'post_filter' => [
'term' => [
'field' => 'value',
],
],
], $query->toArray());
}

/**
* @group functional
*/
Expand Down