NestedQuery   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 2
b 0
f 0
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 0 3 1
A toArray() 0 19 3
A setPath() 0 4 1
1
<?php namespace Nord\Lumen\Elasticsearch\Search\Query\Joining;
2
3
use Nord\Lumen\Elasticsearch\Exceptions\InvalidArgument;
4
5
/**
6
 * Nested query allows to query nested objects / docs (see nested mapping).
7
 *
8
 * The query is executed against the nested objects / docs as if they were indexed as separate docs (they are,
9
 * internally) and resulting in the root parent doc (or parent nested mapping).
10
 *
11
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html
12
 */
13
class NestedQuery extends AbstractQuery
14
{
15
    /**
16
     * @var string
17
     */
18
    private $path;
19
20
    /**
21
     * @inheritdoc
22
     * @throws InvalidArgument
23
     */
24
    public function toArray()
25
    {
26
        $query = $this->getQuery();
27
28
        if ($query === null) {
29
            throw new InvalidArgument('Query must be set');
30
        }
31
        
32
        $nested = [
33
            'path'  => $this->getPath(),
34
            'query' => $query->toArray(),
35
        ];
36
37
        $scoreMode = $this->getScoreMode();
38
        if (null !== $scoreMode) {
39
            $nested['score_mode'] = $scoreMode;
40
        }
41
42
        return ['nested' => $nested];
43
    }
44
45
    /**
46
     * @param string $path
47
     * @return NestedQuery
48
     */
49
    public function setPath($path)
50
    {
51
        $this->path = $path;
52
        return $this;
53
    }
54
55
56
    /**
57
     * @return string
58
     */
59
    public function getPath()
60
    {
61
        return $this->path;
62
    }
63
}
64