1 | <?php |
||
22 | { |
||
23 | public const NAME = 'query'; |
||
24 | |||
25 | private ?BoolQuery $bool = null; |
||
|
|||
26 | |||
27 | private bool $filtersSet = false; |
||
28 | |||
29 | public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []) |
||
30 | { |
||
31 | if (!$this->filtersSet && $this->hasReference('filter_query')) { |
||
32 | /** @var BuilderInterface $filter */ |
||
33 | $filter = $this->getReference('filter_query'); |
||
34 | $this->addToBool($filter, BoolQuery::FILTER); |
||
35 | $this->filtersSet = true; |
||
36 | } |
||
37 | |||
38 | if (!$this->bool) { |
||
39 | return null; |
||
40 | } |
||
41 | |||
42 | return $this->bool->toArray(); |
||
43 | } |
||
44 | |||
45 | public function add(BuilderInterface $builder, string $key = null): string |
||
46 | { |
||
47 | return $this->addToBool($builder, BoolQuery::MUST, $key); |
||
48 | } |
||
49 | |||
50 | public function addToBool(BuilderInterface $builder, ?string $boolType = null, ?string $key = null): string |
||
51 | { |
||
52 | if (!$this->bool) { |
||
53 | $this->bool = new BoolQuery(); |
||
54 | } |
||
55 | |||
56 | return $this->bool->add($builder, $boolType, $key); |
||
57 | } |
||
58 | |||
59 | public function getOrder(): int |
||
60 | { |
||
61 | return 2; |
||
62 | } |
||
63 | |||
64 | public function getBool(): ?BoolQuery |
||
65 | { |
||
66 | return $this->bool; |
||
67 | } |
||
68 | |||
69 | public function getAll($boolType = null): array |
||
70 | { |
||
71 | return $this->bool->getQueries($boolType); |
||
72 | } |
||
73 | } |
||
74 |