Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| SingleAggResultsType | |
0.00% |
0 / 9 |
|
0.00% |
0 / 6 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSourceFiltering | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFields | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getHighlightingConfiguration | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| transformElasticsearchResult | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| createEmptyResult | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace CirrusSearch\Search; |
| 4 | |
| 5 | use Elastica\ResultSet as ElasticaResultSet; |
| 6 | |
| 7 | /** |
| 8 | * Result type for aggregations. |
| 9 | */ |
| 10 | class SingleAggResultsType implements ResultsType { |
| 11 | /** @var string Name of aggregation */ |
| 12 | private $name; |
| 13 | |
| 14 | /** @param string $name Name of aggregation to return */ |
| 15 | public function __construct( $name ) { |
| 16 | $this->name = $name; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @return false|string|array corresponding to Elasticsearch source filtering syntax |
| 21 | */ |
| 22 | public function getSourceFiltering() { |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | /** @inheritDoc */ |
| 27 | public function getFields() { |
| 28 | return []; |
| 29 | } |
| 30 | |
| 31 | /** @inheritDoc */ |
| 32 | public function getHighlightingConfiguration( array $extraHighlightFields ) { |
| 33 | return null; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @param ElasticaResultSet $resultSet |
| 38 | * @return mixed|null Type depends on the aggregation performed. For |
| 39 | * a sum this will return an integer. |
| 40 | */ |
| 41 | public function transformElasticsearchResult( ElasticaResultSet $resultSet ) { |
| 42 | $aggs = $resultSet->getAggregations(); |
| 43 | if ( isset( $aggs[$this->name] ) ) { |
| 44 | return $aggs[$this->name]['value']; |
| 45 | } |
| 46 | return $this->createEmptyResult(); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @return null |
| 51 | */ |
| 52 | public function createEmptyResult() { |
| 53 | return null; |
| 54 | } |
| 55 | } |