Passed
Push — develop ( f2149c...9e9b3a )
by Sam
01:50 queued 17s
created

MultiMatchQuery::getTieBreaker()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace Nord\Lumen\Elasticsearch\Search\Query\FullText;
2
3
use Nord\Lumen\Elasticsearch\Search\Query\Traits\HasFields;
4
use Nord\Lumen\Elasticsearch\Search\Traits\HasTieBreaker;
5
6
/**
7
 * The multi_match query builds on the match query to allow multi-field queries.
8
 *
9
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html
10
 */
11
class MultiMatchQuery extends MatchQuery
12
{
13
    use HasFields;
14
    use HasTieBreaker;
15
    
16
    const TYPE_BEST_FIELDS   = 'best_fields';
17
    const TYPE_MOST_FIELDS   = 'most_fields';
18
    const TYPE_CROSS_FIELDS  = 'cross_fields';
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function toArray()
24
    {
25
        $multiMatch = [
26
            'query'  => $this->getValue(),
27
            'fields' => $this->getFields()
28
        ];
29
30
        $multiMatch = $this->applyOptions($multiMatch);
31
32
        return ['multi_match' => $multiMatch];
33
    }
34
35
    /**
36
     * @param array $match
37
     * @return array
38
     */
39
    protected function applyOptions(array $match)
40
    {
41
        $multiMatch = parent::applyOptions($match);
42
43
        $tieBreaker = $this->getTieBreaker();
44
        if (!is_null($tieBreaker)) {
0 ignored issues
show
introduced by
The condition is_null($tieBreaker) is always false.
Loading history...
45
            $multiMatch['tie_breaker'] = $tieBreaker;
46
        }
47
48
        return $multiMatch;
49
    }
50
}
51