1 | <?php |
||
2 | |||
3 | namespace olvlvl\ElasticsearchDSL\Query\Compound; |
||
4 | |||
5 | use ICanBoogie\Accessor\AccessorTrait; |
||
6 | use olvlvl\ElasticsearchDSL\Query\Compound\BoolQuery\FilterQuery; |
||
7 | use olvlvl\ElasticsearchDSL\Query\Compound\BoolQuery\MustNotQuery; |
||
8 | use olvlvl\ElasticsearchDSL\Query\Compound\BoolQuery\MustQuery; |
||
9 | use olvlvl\ElasticsearchDSL\Query\Compound\BoolQuery\ShouldQuery; |
||
10 | use olvlvl\ElasticsearchDSL\Query\Option\BoostOption; |
||
11 | use olvlvl\ElasticsearchDSL\Query\Option\HasBoostOption; |
||
12 | use olvlvl\ElasticsearchDSL\Query\QueryAbstract; |
||
13 | |||
14 | /** |
||
15 | * @property-read FilterQuery $filter |
||
16 | * @property-read MustQuery $must |
||
17 | * @property-read ShouldQuery $should |
||
18 | * @property-read MustNotQuery $must_not |
||
19 | * |
||
20 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-bool-query.html |
||
21 | */ |
||
22 | class BoolQuery extends QueryAbstract implements HasBoostOption |
||
23 | { |
||
24 | use AccessorTrait; |
||
25 | use BoostOption; |
||
26 | |||
27 | const NAME = 'bool'; |
||
28 | |||
29 | /** |
||
30 | * @var MustQuery |
||
31 | */ |
||
32 | private $must; |
||
33 | |||
34 | /** |
||
35 | * @return MustQuery |
||
36 | */ |
||
37 | protected function get_must(): MustQuery |
||
38 | { |
||
39 | return $this->must; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @var FilterQuery |
||
44 | */ |
||
45 | private $filter; |
||
46 | |||
47 | /** |
||
48 | * @return FilterQuery |
||
49 | */ |
||
50 | protected function get_filter(): FilterQuery |
||
51 | { |
||
52 | return $this->filter; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @var ShouldQuery |
||
57 | */ |
||
58 | private $should; |
||
59 | |||
60 | /** |
||
61 | * @return ShouldQuery |
||
62 | */ |
||
63 | protected function get_should(): ShouldQuery |
||
64 | { |
||
65 | return $this->should; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @var MustNotQuery |
||
70 | */ |
||
71 | private $must_not; |
||
72 | |||
73 | /** |
||
74 | * @return MustNotQuery |
||
75 | */ |
||
76 | protected function get_must_not(): MustNotQuery |
||
77 | { |
||
78 | return $this->must_not; |
||
79 | } |
||
80 | |||
81 | public function __construct() |
||
82 | { |
||
83 | $this->must = new MustQuery(); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
84 | $this->filter = new FilterQuery(); |
||
0 ignored issues
–
show
|
|||
85 | $this->should = new ShouldQuery(); |
||
0 ignored issues
–
show
|
|||
86 | $this->must_not = new MustNotQuery(); |
||
0 ignored issues
–
show
|
|||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @param int|null $minimum_should_match |
||
91 | * |
||
92 | * @return $this |
||
93 | */ |
||
94 | public function minimum_should_match(?int $minimum_should_match) |
||
95 | { |
||
96 | $this->options[__FUNCTION__] = $minimum_should_match; |
||
97 | |||
98 | return $this; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @inheritdoc |
||
103 | */ |
||
104 | public function jsonSerialize() |
||
105 | { |
||
106 | return [ static::NAME => array_filter( |
||
107 | |||
108 | $this->must->jsonSerialize() + |
||
109 | $this->filter->jsonSerialize() + |
||
110 | $this->should->jsonSerialize() + |
||
111 | $this->must_not->jsonSerialize() |
||
112 | |||
113 | ) + parent::jsonSerialize() ]; |
||
114 | } |
||
115 | } |
||
116 |