Skip to content

Commit

Permalink
Do not modify query in Search::count (ruflin#1264)
Browse files Browse the repository at this point in the history
* Do not modify query in Search::count

* Update changelog
  • Loading branch information
XWB authored and Marek Hernik committed Jul 24, 2017
1 parent 9823d11 commit 42ccdc7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file based on the
- Fix reading bool index settings like `\Elastica\Index\Settings::getBlocksWrite`. Elasticsearch returns all settings as strings and does not normalize bool values.
The getters now return the right bool value for whichever string representation is used like 'true', '1', 'on', 'yes'.
- Fix for QueryBuilder version check `\Elastica\QueryBuilder\Version\Version240.php` added all new query types to queries array.
- Do not modify the original query in `\Elastica\Search::count`.

### Added

Expand Down
3 changes: 2 additions & 1 deletion lib/Elastica/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ public function count($query = '', $fullResult = false)
{
$this->setOptionsAndQuery(null, $query);

$query = $this->getQuery();
// Clone the object as we do not want to modify the original query.
$query = clone $this->getQuery();
$query->setSize(0);
$path = $this->getPath();

Expand Down
16 changes: 16 additions & 0 deletions test/Elastica/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,4 +578,20 @@ public function testIgnoreUnavailableOption()
$results = $search->search($query, [Search::OPTION_SEARCH_IGNORE_UNAVAILABLE => true]);
$this->assertInstanceOf(ResultSet::class, $results);
}

/**
* @group functional
*/
public function testQuerySizeAfterCount()
{
$client = $this->_getClient();
$search = new Search($client);

$query = new Query(new MatchAll());
$query->setSize(25);

$search->count($query);

$this->assertEquals(25, $query->getParam('size'));
}
}

0 comments on commit 42ccdc7

Please sign in to comment.