Skip to content

Commit

Permalink
Add method setTrackTotalHits to Elastica\Query (ruflin#1663) (ruflin#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alamirault authored and ruflin committed Sep 23, 2019
1 parent 68e6db3 commit 837b11d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ All notable changes to this project will be documented in this file based on the
* Support string DSN in `\Elastica\Client` constructor for config argument [#1640](https://github.com/ruflin/Elastica/issues/1640)
* Move Client configuration in a dedicated class
* Added `callable` type hinting to `$callback` in `Client` constructor. [#1659](https://github.com/ruflin/Elastica/pull/1659)
* Added `setTrackTotalHits` method to `Elastica\Query`[#1663](https://github.com/ruflin/Elastica/issues/1663)

### Improvements
* Added `native_function_invocation` CS rule [#1606](https://github.com/ruflin/Elastica/pull/1606)
Expand Down
14 changes: 14 additions & 0 deletions lib/Elastica/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,18 @@ public function setCollapse(Collapse $collapse): self
{
return $this->setParam('collapse', $collapse);
}

/**
* Adds a track_total_hits argument.
*
* @param bool|int $trackTotalHits OPTIONAL Track total hits parameter (default = true)
*
* @return $this
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-track-total-hits
*/
public function setTrackTotalHits($trackTotalHits = true)
{
return $this->setParam('track_total_hits', $trackTotalHits);
}
}
12 changes: 12 additions & 0 deletions test/Elastica/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,16 @@ public function testCollapseSecondLevelArrayStructure()
$this->assertArrayHasKey('collapse', $actual);
$this->assertEquals($expected, $actual['collapse']);
}

/**
* @group unit
*/
public function testSetTrackTotalHits()
{
$query = new Query();
$param = false;
$query->setTrackTotalHits($param);

$this->assertEquals($param, $query->getParam('track_total_hits'));
}
}

0 comments on commit 837b11d

Please sign in to comment.