Elastica\Aggregation\TopHits::setHighlight PHP Method

setHighlight() public method

Sets highlight arguments for the results.
public setHighlight ( array $highlightArgs )
$highlightArgs array
    public function setHighlight(array $highlightArgs)
    {
        return $this->setParam('highlight', $highlightArgs);
    }

Usage Example

Example #1
0
 /**
  * @group functional
  */
 public function testAggregateWithHighlight()
 {
     $queryString = new SimpleQueryString('linux', array('title'));
     $aggr = new TopHits('top_tag_hits');
     $aggr->setHighlight(array('fields' => array('title' => new \stdClass())));
     $query = new Query($queryString);
     $query->addAggregation($aggr);
     $resultSet = $this->_getIndexForTest()->search($query);
     $aggrResult = $resultSet->getAggregation('top_tag_hits');
     foreach ($aggrResult['hits']['hits'] as $doc) {
         $this->assertArrayHasKey('highlight', $doc);
         $this->assertRegExp('#<em>linux</em>#', $doc['highlight']['title'][0]);
     }
 }