diff --git a/test/Elastica/QueryTest.php b/test/Elastica/QueryTest.php index 0235cc3e35..48425164d0 100644 --- a/test/Elastica/QueryTest.php +++ b/test/Elastica/QueryTest.php @@ -547,7 +547,7 @@ public function testCollapseSecondLevelArrayStructure() /** * @group unit */ - public function testSetTrackTotalHits() + public function testSetTrackTotalHitsIsInParams() { $query = new Query(); $param = false; @@ -555,4 +555,45 @@ public function testSetTrackTotalHits() $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()); + } }