Skip to content

Commit

Permalink
Add functional test to Query method setTrackTotalHits (ruflin#1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamirault authored and ruflin committed Sep 25, 2019
1 parent 837b11d commit 63c30d2
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion test/Elastica/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,53 @@ public function testCollapseSecondLevelArrayStructure()
/**
* @group unit
*/
public function testSetTrackTotalHits()
public function testSetTrackTotalHitsIsInParams()
{
$query = new Query();
$param = false;
$query->setTrackTotalHits($param);

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

/**
* @group functional
*/
public function testSetTrackTotalHits()
{
$index = $this->_createIndex();
$type = $index->getType('_doc');

$mapping = new Mapping($type,
[
'firstname' => ['type' => 'text', 'fielddata' => true],
]
);
$type->setMapping($mapping);

$documents = [];
for ($i = 0; $i < 50; ++$i) {
$documents[] = new Document($i, ['firstname' => 'antoine '.$i]);
}

$type->addDocuments($documents);

$queryTerm = new Term();
$queryTerm->setTerm('firstname', 'antoine');

$index->refresh();

$query = Query::create($queryTerm);

$resultSet = $type->search($query);
$this->assertEquals(50, $resultSet->getTotalHits());

$query->setTrackTotalHits(false);
$resultSet = $type->search($query);
$this->assertEquals(0, $resultSet->getTotalHits());

$query->setTrackTotalHits(25);
$resultSet = $type->search($query);
$this->assertEquals(25, $resultSet->getTotalHits());
}
}

0 comments on commit 63c30d2

Please sign in to comment.