Completed
Branch feature/job-plans (e266db)
by Adam
05:31
created

TopSpot   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 33
rs 10
wmc 1
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B apply() 0 26 1
1
<?php
2
3
namespace Coyote\Services\Elasticsearch\Aggs\Job;
4
5
use Coyote\Services\Elasticsearch\DslInterface;
6
use Coyote\Services\Elasticsearch\QueryBuilderInterface;
7
8
class TopSpot implements DslInterface
9
{
10
    /**
11
     * @param QueryBuilderInterface $queryBuilder
12
     * @return array
13
     */
14
    public function apply(QueryBuilderInterface $queryBuilder)
15
    {
16
        $body = $queryBuilder->getBody();
17
18
        $body['aggs']['premium_listing'] = [
19
            'terms' => [
20
                'field' => 'is_on_top',
21
                'size' => 3,
22
                'order' => [
23
                    'top_hit' => 'desc'
24
                ]
25
            ],
26
            'aggs' => [
27
                'premium_listing' => [
28
                    'top_hits' => (object) []
29
                ],
30
                'top_hit' => [
31
                    'max' => [
32
                        'script' => ['inline' => '_score']
33
                    ]
34
                ]
35
            ]
36
        ];
37
38
        return $body;
39
    }
40
}
41