Elastica\Aggregation\TopHits::setSort PHP Method

setSort() public method

How the top matching hits should be sorted. By default the hits are sorted by the score of the main query.
public setSort ( array $sortArgs )
$sortArgs array
    public function setSort(array $sortArgs)
    {
        return $this->setParam('sort', $sortArgs);
    }

Usage Example

Example #1
0
 /**
  * @group functional
  */
 public function testAggregateTwoDocumentPerTagWithOffset()
 {
     $aggr = new TopHits('top_tag_hits');
     $aggr->setSize(2);
     $aggr->setFrom(1);
     $aggr->setSort(array('last_activity_date' => array('order' => 'desc')));
     $resultDocs = array();
     $outerAggrResult = $this->getOuterAggregationResult($aggr);
     foreach ($outerAggrResult['buckets'] as $bucket) {
         foreach ($bucket['top_tag_hits']['hits']['hits'] as $doc) {
             $resultDocs[] = $doc['_id'];
         }
     }
     $this->assertEquals(array(2, 4), $resultDocs);
 }