Skip to content

Commit e9e0a5c

Browse files
committed
Added nested query
1 parent 3a92e0a commit e9e0a5c

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

src/Query/Nested.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\ElasticQuery\Query;
4+
5+
class Nested implements \Spameri\ElasticQuery\Query\LeafQueryInterface
6+
{
7+
8+
private string $path;
9+
10+
private \Spameri\ElasticQuery\Query\QueryCollection $query;
11+
12+
13+
public function __construct(
14+
string $path,
15+
?\Spameri\ElasticQuery\Query\QueryCollection $query = NULL
16+
) {
17+
$this->path = $path;
18+
19+
if ($query === NULL) {
20+
$query = new \Spameri\ElasticQuery\Query\QueryCollection();
21+
}
22+
23+
$this->query = $query;
24+
}
25+
26+
27+
public function key(): string
28+
{
29+
return 'nested_' . $this->path;
30+
}
31+
32+
33+
public function toArray(): array
34+
{
35+
return [
36+
'nested' => [
37+
'path' => $this->path,
38+
'query' => [
39+
'bool' => $this->query->toArray(),
40+
],
41+
],
42+
];
43+
}
44+
45+
46+
public function getQuery(): \Spameri\ElasticQuery\Query\QueryCollection
47+
{
48+
return $this->query;
49+
}
50+
51+
}

0 commit comments

Comments
 (0)