|
1 | | -<?php declare(strict_types=1); |
2 | | - |
3 | | -namespace Spameri\ElasticQuery; |
4 | | - |
5 | | - |
6 | | -class ElasticQuery implements \Spameri\ElasticQuery\Entity\ArrayInterface |
7 | | -{ |
8 | | - |
9 | | - /** |
10 | | - * @var \Spameri\ElasticQuery\Query\QueryCollection |
11 | | - */ |
12 | | - private $query; |
13 | | - |
14 | | - /** |
15 | | - * @var \Spameri\ElasticQuery\Filter\FilterCollection |
16 | | - */ |
17 | | - private $filter; |
18 | | - |
19 | | - /** |
20 | | - * @var \Spameri\ElasticQuery\Options\SortCollection |
21 | | - */ |
22 | | - private $sort; |
23 | | - |
24 | | - /** |
25 | | - * @var \Spameri\ElasticQuery\Aggregation\AggregationCollection |
26 | | - */ |
27 | | - private $aggregation; |
28 | | - |
29 | | - /** |
30 | | - * @var \Spameri\ElasticQuery\Options |
31 | | - */ |
32 | | - private $options; |
33 | | - |
34 | | - |
35 | | - public function __construct( |
36 | | - ?\Spameri\ElasticQuery\Query\QueryCollection $query = NULL |
37 | | - , ?\Spameri\ElasticQuery\Filter\FilterCollection $filter = NULL |
38 | | - , ?\Spameri\ElasticQuery\Options\SortCollection $sort = NULL |
39 | | - , ?\Spameri\ElasticQuery\Aggregation\AggregationCollection $aggregation = NULL |
40 | | - , ?Options $options = NULL |
41 | | - ) |
42 | | - { |
43 | | - if ( ! $query) { |
44 | | - $query = new \Spameri\ElasticQuery\Query\QueryCollection(); |
45 | | - } |
46 | | - if ( ! $filter) { |
47 | | - $filter = new \Spameri\ElasticQuery\Filter\FilterCollection(); |
48 | | - } |
49 | | - if ( ! $sort) { |
50 | | - $sort = new \Spameri\ElasticQuery\Options\SortCollection(); |
51 | | - } |
52 | | - if ( ! $aggregation) { |
53 | | - $aggregation = new \Spameri\ElasticQuery\Aggregation\AggregationCollection(); |
54 | | - } |
55 | | - if ( ! $options) { |
56 | | - $options = new Options(); |
57 | | - } |
58 | | - $this->query = $query; |
59 | | - $this->filter = $filter; |
60 | | - $this->sort = $sort; |
61 | | - $this->aggregation = $aggregation; |
62 | | - $this->options = $options; |
63 | | - } |
64 | | - |
65 | | - |
66 | | - public function query() : \Spameri\ElasticQuery\Query\QueryCollection |
67 | | - { |
68 | | - return $this->query; |
69 | | - } |
70 | | - |
71 | | - |
72 | | - public function filter() : \Spameri\ElasticQuery\Filter\FilterCollection |
73 | | - { |
74 | | - return $this->filter; |
75 | | - } |
76 | | - |
77 | | - |
78 | | - public function aggregation() : \Spameri\ElasticQuery\Aggregation\AggregationCollection |
79 | | - { |
80 | | - return $this->aggregation; |
81 | | - } |
82 | | - |
83 | | - |
84 | | - public function options() : \Spameri\ElasticQuery\Options |
85 | | - { |
86 | | - return $this->options; |
87 | | - } |
88 | | - |
89 | | - |
90 | | - public function toArray() : array |
91 | | - { |
92 | | - $array = $this->options->toArray(); |
93 | | - |
94 | | - $queryArray = $this->query->toArray(); |
95 | | - if ($queryArray) { |
96 | | - $array['query'] = $queryArray; |
97 | | - } |
98 | | - |
99 | | - $filterArray = $this->filter->toArray(); |
100 | | - if ($filterArray) { |
101 | | - $array['filter'] = $filterArray; |
102 | | - } |
103 | | - |
104 | | - $sortArray = $this->sort->toArray(); |
105 | | - if ($sortArray) { |
106 | | - $array['sort'] = $sortArray; |
107 | | - } |
108 | | - |
109 | | - $aggregation = $this->aggregation->toArray(); |
110 | | - if ($aggregation) { |
111 | | - $array['aggs'] = $aggregation; |
112 | | - } |
113 | | - |
114 | | - return $array; |
115 | | - } |
116 | | - |
117 | | -} |
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace Spameri\ElasticQuery; |
| 4 | + |
| 5 | + |
| 6 | +class ElasticQuery implements \Spameri\ElasticQuery\Entity\ArrayInterface |
| 7 | +{ |
| 8 | + |
| 9 | + /** |
| 10 | + * @var \Spameri\ElasticQuery\Query\QueryCollection |
| 11 | + */ |
| 12 | + private $query; |
| 13 | + |
| 14 | + /** |
| 15 | + * @var \Spameri\ElasticQuery\Filter\FilterCollection |
| 16 | + */ |
| 17 | + private $filter; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var \Spameri\ElasticQuery\Options\SortCollection |
| 21 | + */ |
| 22 | + private $sort; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var \Spameri\ElasticQuery\Aggregation\AggregationCollection |
| 26 | + */ |
| 27 | + private $aggregation; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var \Spameri\ElasticQuery\Options |
| 31 | + */ |
| 32 | + private $options; |
| 33 | + |
| 34 | + |
| 35 | + public function __construct( |
| 36 | + ?\Spameri\ElasticQuery\Query\QueryCollection $query = NULL |
| 37 | + , ?\Spameri\ElasticQuery\Filter\FilterCollection $filter = NULL |
| 38 | + , ?\Spameri\ElasticQuery\Options\SortCollection $sort = NULL |
| 39 | + , ?\Spameri\ElasticQuery\Aggregation\AggregationCollection $aggregation = NULL |
| 40 | + , ?Options $options = NULL |
| 41 | + ) |
| 42 | + { |
| 43 | + if ( ! $query) { |
| 44 | + $query = new \Spameri\ElasticQuery\Query\QueryCollection(); |
| 45 | + } |
| 46 | + if ( ! $filter) { |
| 47 | + $filter = new \Spameri\ElasticQuery\Filter\FilterCollection(); |
| 48 | + } |
| 49 | + if ( ! $sort) { |
| 50 | + $sort = new \Spameri\ElasticQuery\Options\SortCollection(); |
| 51 | + } |
| 52 | + if ( ! $aggregation) { |
| 53 | + $aggregation = new \Spameri\ElasticQuery\Aggregation\AggregationCollection(); |
| 54 | + } |
| 55 | + if ( ! $options) { |
| 56 | + $options = new Options(); |
| 57 | + } |
| 58 | + $this->query = $query; |
| 59 | + $this->filter = $filter; |
| 60 | + $this->sort = $sort; |
| 61 | + $this->aggregation = $aggregation; |
| 62 | + $this->options = $options; |
| 63 | + } |
| 64 | + |
| 65 | + |
| 66 | + public function query() : \Spameri\ElasticQuery\Query\QueryCollection |
| 67 | + { |
| 68 | + return $this->query; |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + public function filter() : \Spameri\ElasticQuery\Filter\FilterCollection |
| 73 | + { |
| 74 | + return $this->filter; |
| 75 | + } |
| 76 | + |
| 77 | + |
| 78 | + public function aggregation() : \Spameri\ElasticQuery\Aggregation\AggregationCollection |
| 79 | + { |
| 80 | + return $this->aggregation; |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | + public function options() : \Spameri\ElasticQuery\Options |
| 85 | + { |
| 86 | + return $this->options; |
| 87 | + } |
| 88 | + |
| 89 | + |
| 90 | + public function toArray() : array |
| 91 | + { |
| 92 | + $array = $this->options->toArray(); |
| 93 | + |
| 94 | + $queryArray = $this->query->toArray(); |
| 95 | + if ($queryArray) { |
| 96 | + $array['query'] = $queryArray; |
| 97 | + } |
| 98 | + |
| 99 | + $filterArray = $this->filter->toArray(); |
| 100 | + if ($filterArray) { |
| 101 | + $array['filter'] = $filterArray; |
| 102 | + } |
| 103 | + |
| 104 | + $sortArray = $this->sort->toArray(); |
| 105 | + if ($sortArray) { |
| 106 | + $array['sort'] = $sortArray; |
| 107 | + } |
| 108 | + |
| 109 | + $aggregation = $this->aggregation->toArray(); |
| 110 | + if ($aggregation) { |
| 111 | + $array['aggs'] = $aggregation; |
| 112 | + } |
| 113 | + |
| 114 | + return $array; |
| 115 | + } |
| 116 | + |
| 117 | +} |
0 commit comments