diff --git a/CHANGELOG.md b/CHANGELOG.md index dbf08977f7..b3e7a69d8f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/Elastica/Query.php b/lib/Elastica/Query.php index d49fb5206e..3c55998d63 100644 --- a/lib/Elastica/Query.php +++ b/lib/Elastica/Query.php @@ -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); + } } diff --git a/test/Elastica/QueryTest.php b/test/Elastica/QueryTest.php index ffb92df879..0235cc3e35 100644 --- a/test/Elastica/QueryTest.php +++ b/test/Elastica/QueryTest.php @@ -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')); + } }