Completed
Pull Request — master (#148)
by Simonas
02:51
created

SamplerAggregation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchDSL\Aggregation\Bucketing;
13
14
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
15
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;
16
17
/**
18
 * Class representing geo bounds aggregation.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-aggregations-bucket-sampler-aggregation.html
21
 */
22
class SamplerAggregation extends AbstractAggregation
23
{
24
    use BucketingTrait;
25
26
    /**
27
     * Defines how many results will be received from each shard
28
     * @param string $shardSize
29
     */
30
    private $shardSize;
31
32
    /**
33
     * Inner aggregations container init.
34
     *
35
     * @param string $name
36
     * @param string $field
37
     * @param int    $shardSize
38
     */
39
    public function __construct(
40
        $name,
41
        $field = null,
42
        $shardSize = null
43
    ) {
44
        parent::__construct($name);
45
46
        $this->setField($field);
47
        $this->setShardSize($shardSize);
48
    }
49
50
    /**
51
     * @return int
52
     */
53
    public function getShardSize()
54
    {
55
        return $this->shardSize;
56
    }
57
58
    /**
59
     * @param int $shardSize
60
     */
61
    public function setShardSize($shardSize)
62
    {
63
        $this->shardSize = $shardSize;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getType()
70
    {
71
        return 'sampler';
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getArray()
78
    {
79
        $out = array_filter(
80
            [
81
                'field' => $this->getField(),
82
                'shard_size' => $this->getShardSize(),
83
            ]
84
        );
85
86
        return $out;
87
    }
88
}
89