1 | <?php |
||
24 | class NestedInnerHit implements BuilderInterface |
||
25 | { |
||
26 | use ParametersTrait; |
||
27 | use NameAwareTrait; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | private $path; |
||
33 | |||
34 | /** |
||
35 | * @var Search |
||
36 | */ |
||
37 | private $query; |
||
38 | |||
39 | /** |
||
40 | * Inner hits container init. |
||
41 | * |
||
42 | * @param string $name |
||
43 | * @param string $path |
||
44 | * @param Search $query |
||
45 | */ |
||
46 | public function __construct($name, $path, Search $query = null) |
||
52 | |||
53 | /** |
||
54 | * @return string |
||
55 | */ |
||
56 | public function getPath() |
||
60 | |||
61 | /** |
||
62 | * @param string $path |
||
63 | * |
||
64 | * @return $this |
||
65 | */ |
||
66 | public function setPath($path) |
||
72 | |||
73 | /** |
||
74 | * @return Search |
||
75 | */ |
||
76 | public function getSearch() |
||
77 | { |
||
78 | return $this->query; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @param Search $query |
||
83 | * |
||
84 | * @return $this |
||
85 | */ |
||
86 | public function setSearch(Search $query = null) |
||
87 | { |
||
88 | $this->query = $query; |
||
89 | |||
90 | return $this; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | public function getType() |
||
97 | { |
||
98 | return 'nested'; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | public function toArray() |
||
105 | { |
||
106 | $out = $this->getSearch() ? $this->getSearch()->toArray() : new \stdClass(); |
||
107 | |||
108 | $out = [ |
||
109 | $this->getPathType() => [ |
||
110 | $this->getPath() => $out , |
||
111 | ], |
||
112 | ]; |
||
113 | |||
114 | return $out; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Returns 'path' for nested and 'type' for parent inner hits |
||
119 | * |
||
120 | * @return null|string |
||
121 | */ |
||
122 | private function getPathType() |
||
136 | } |
||
137 |