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

Add method setTrackTotalHits to Elastica\Query (#1663) #1664

Merged
merged 1 commit into from
Sep 23, 2019
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 @@ -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'));
}
}