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 | public function getFields() { |
27 | return []; |
28 | } |
29 | |
30 | public function getHighlightingConfiguration( array $extraHighlightFields ) { |
31 | return null; |
32 | } |
33 | |
34 | /** |
35 | * @param ElasticaResultSet $resultSet |
36 | * @return mixed|null Type depends on the aggregation performed. For |
37 | * a sum this will return an integer. |
38 | */ |
39 | public function transformElasticsearchResult( ElasticaResultSet $resultSet ) { |
40 | $aggs = $resultSet->getAggregations(); |
41 | if ( isset( $aggs[$this->name] ) ) { |
42 | return $aggs[$this->name]['value']; |
43 | } |
44 | return $this->createEmptyResult(); |
45 | } |
46 | |
47 | /** |
48 | * @return null |
49 | */ |
50 | public function createEmptyResult() { |
51 | return null; |
52 | } |
53 | } |