|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace ONGR\ElasticsearchDSL\Sort; |
|
15
|
|
|
|
|
16
|
|
|
use ONGR\ElasticsearchDSL\BuilderInterface; |
|
17
|
|
|
use ONGR\ElasticsearchDSL\ParametersTrait; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Represents Elasticsearch "nested" sort filter. |
|
21
|
|
|
* |
|
22
|
|
|
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/filter-dsl-nested-filter.html |
|
23
|
|
|
*/ |
|
24
|
|
|
class NestedSort implements BuilderInterface |
|
25
|
|
|
{ |
|
26
|
|
|
use ParametersTrait; |
|
27
|
|
|
|
|
28
|
|
|
private ?BuilderInterface $nestedFilter = null; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
public function __construct( |
|
31
|
|
|
private string $path, |
|
32
|
|
|
private ?BuilderInterface $filter = null, |
|
33
|
|
|
array $parameters = [] |
|
34
|
|
|
) { |
|
35
|
|
|
$this->setParameters($parameters); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getType(): string |
|
39
|
|
|
{ |
|
40
|
|
|
return 'nested'; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function toArray(): array |
|
44
|
|
|
{ |
|
45
|
|
|
$output = [ |
|
46
|
|
|
'path' => $this->path, |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
if ($this->filter) { |
|
50
|
|
|
$output['filter'] = $this->filter->toArray(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if ($this->nestedFilter) { |
|
54
|
|
|
$output[$this->getType()] = $this->nestedFilter->toArray(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $this->processArray($output); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getFilter(): ?BuilderInterface |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->filter; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getPath(): string |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->path; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getNestedFilter(): ?BuilderInterface |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->nestedFilter; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function setNestedFilter(?BuilderInterface $nestedFilter): static |
|
76
|
|
|
{ |
|
77
|
|
|
$this->nestedFilter = $nestedFilter; |
|
78
|
|
|
|
|
79
|
|
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|