Completed
Push — master ( 6c9334...f3ba17 )
by Simonas
02:26
created

BoostingQuery   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getType() 0 4 1
A toArray() 0 10 1
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\Query\Compound;
13
14
use ONGR\ElasticsearchDSL\BuilderInterface;
15
16
/**
17
 * Represents Elasticsearch "boosting" query.
18
 *
19
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html
20
 */
21
class BoostingQuery implements BuilderInterface
22
{
23
    /**
24
     * @var BuilderInterface
25
     */
26
    private $positive;
27
28
    /**
29
     * @var BuilderInterface
30
     */
31
    private $negative;
32
33
    /**
34
     * @var int|float
35
     */
36
    private $negativeBoost;
37
38
    /**
39
     * @param BuilderInterface $positive
40
     * @param BuilderInterface $negative
41
     * @param int|float        $negativeBoost
42
     */
43
    public function __construct(BuilderInterface $positive, BuilderInterface $negative, $negativeBoost)
44
    {
45
        $this->positive = $positive;
46
        $this->negative = $negative;
47
        $this->negativeBoost = $negativeBoost;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getType()
54
    {
55
        return 'boosting';
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function toArray()
62
    {
63
        $query = [
64
            'positive' => $this->positive->toArray(),
65
            'negative' => $this->negative->toArray(),
66
            'negative_boost' => $this->negativeBoost,
67
        ];
68
69
        return [$this->getType() => $query];
70
    }
71
}
72