66class ElasticQuery implements \Spameri \ElasticQuery \Entity \ArrayInterface
77{
88
9- /**
10- * @var \Spameri\ElasticQuery\Query\QueryCollection
11- */
12- private $ query ;
9+ private \Spameri \ElasticQuery \Query \QueryCollection $ query ;
1310
14- /**
15- * @var \Spameri\ElasticQuery\Filter\FilterCollection
16- */
17- private $ filter ;
11+ private \Spameri \ElasticQuery \Filter \FilterCollection $ filter ;
1812
19- /**
20- * @var \Spameri\ElasticQuery\Options\SortCollection
21- */
22- private $ sort ;
13+ private \Spameri \ElasticQuery \Options \SortCollection $ sort ;
2314
24- /**
25- * @var \Spameri\ElasticQuery\Aggregation\AggregationCollection
26- */
27- private $ aggregation ;
15+ private \Spameri \ElasticQuery \Aggregation \AggregationCollection $ aggregation ;
2816
29- /**
30- * @var \Spameri\ElasticQuery\Options
31- */
32- private $ options ;
17+ private \Spameri \ElasticQuery \Options $ options ;
18+
19+ private ?\Spameri \ElasticQuery \Highlight $ highlight ;
20+
21+ private ?\Spameri \ElasticQuery \FunctionScore $ functionScore ;
3322
3423
3524 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
25+ ?\Spameri \ElasticQuery \Query \QueryCollection $ query = NULL ,
26+ ?\Spameri \ElasticQuery \Filter \FilterCollection $ filter = NULL ,
27+ ?\Spameri \ElasticQuery \Options \SortCollection $ sort = NULL ,
28+ ?\Spameri \ElasticQuery \Aggregation \AggregationCollection $ aggregation = NULL ,
29+ ?\Spameri \ElasticQuery \Highlight $ highlight = NULL ,
30+ ?\Spameri \ElasticQuery \FunctionScore $ functionScore = NULL ,
31+ ?\Spameri \ElasticQuery \Options $ options = NULL
4132 )
4233 {
43- if ( ! $ query ) {
34+ if ($ query === NULL ) {
4435 $ query = new \Spameri \ElasticQuery \Query \QueryCollection ();
4536 }
46- if ( ! $ filter ) {
37+ if ($ filter === NULL ) {
4738 $ filter = new \Spameri \ElasticQuery \Filter \FilterCollection ();
4839 }
49- if ( ! $ sort ) {
40+ if ($ sort === NULL ) {
5041 $ sort = new \Spameri \ElasticQuery \Options \SortCollection ();
5142 }
52- if ( ! $ aggregation ) {
43+ if ($ aggregation === NULL ) {
5344 $ aggregation = new \Spameri \ElasticQuery \Aggregation \AggregationCollection ();
5445 }
55- if ( ! $ options ) {
56- $ options = new Options ();
46+ if ($ options === NULL ) {
47+ $ options = new \ Spameri \ ElasticQuery \ Options ();
5748 }
49+
5850 $ this ->query = $ query ;
5951 $ this ->filter = $ filter ;
6052 $ this ->sort = $ sort ;
6153 $ this ->aggregation = $ aggregation ;
6254 $ this ->options = $ options ;
55+ $ this ->highlight = $ highlight ;
56+ $ this ->functionScore = $ functionScore ;
6357 }
6458
6559
@@ -87,6 +81,18 @@ public function options(): \Spameri\ElasticQuery\Options
8781 }
8882
8983
84+ public function highlight (): ?\Spameri \ElasticQuery \Highlight
85+ {
86+ return $ this ->highlight ;
87+ }
88+
89+
90+ public function functionScore (): ?\Spameri \ElasticQuery \FunctionScore
91+ {
92+ return $ this ->functionScore ;
93+ }
94+
95+
9096 public function addMustQuery (\Spameri \ElasticQuery \Query \LeafQueryInterface $ leafQuery ): void
9197 {
9298 $ this ->query ->must ()->add ($ leafQuery );
@@ -126,6 +132,10 @@ public function toArray(): array
126132 $ array ['query ' ] = $ queryArray ;
127133 }
128134
135+ if ($ this ->functionScore !== NULL ) {
136+ $ array ['query ' ] = $ this ->functionScore ->toArray ($ array ['query ' ]);
137+ }
138+
129139 $ filterArray = $ this ->filter ->toArray ();
130140 if ($ filterArray ) {
131141 $ array ['filter ' ] = $ filterArray ;
@@ -141,6 +151,10 @@ public function toArray(): array
141151 $ array ['aggs ' ] = $ aggregation ;
142152 }
143153
154+ if ($ this ->highlight !== NULL ) {
155+ $ array ['highlight ' ] = $ this ->highlight ->toArray ();
156+ }
157+
144158 return $ array ;
145159 }
146160
0 commit comments