File tree Expand file tree Collapse file tree 4 files changed +83
-19
lines changed
Expand file tree Collapse file tree 4 files changed +83
-19
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Spameri \ElasticQuery \Document ;
4+
5+
6+ class Bulk implements \Spameri \ElasticQuery \Entity \ArrayInterface
7+ {
8+
9+ /**
10+ * @var array
11+ */
12+ private $ data ;
13+
14+
15+ public function __construct (
16+ array $ data
17+ )
18+ {
19+ $ this ->data = $ data ;
20+ }
21+
22+
23+ public function toArray () : array
24+ {
25+ return [
26+ 'body ' => $ this ->data ,
27+ ];
28+ }
29+
30+ }
Original file line number Diff line number Diff line change @@ -14,24 +14,39 @@ class ElasticQuery implements \Spameri\ElasticQuery\Entity\ArrayInterface
1414 * @var \Spameri\ElasticQuery\Filter\FilterCollection
1515 */
1616 private $ filter ;
17+ /**
18+ * @var null
19+ */
20+ private $ sort ;
21+ /**
22+ * @var null
23+ */
24+ private $ aggregation ;
25+ /**
26+ * @var int
27+ */
28+ private $ from ;
29+ /**
30+ * @var int
31+ */
32+ private $ size ;
1733
1834
1935 public function __construct (
20- ?\Spameri \ElasticQuery \Query \QueryCollection $ query
21- , ?\Spameri \ElasticQuery \Filter \FilterCollection $ filter
22- , $ aggregation
36+ ?\Spameri \ElasticQuery \Query \QueryCollection $ query = NULL
37+ , ?\Spameri \ElasticQuery \Filter \FilterCollection $ filter = NULL
38+ , $ sort = NULL
39+ , $ aggregation = NULL
40+ , int $ from = NULL
41+ , int $ size = NULL
2342 )
2443 {
25- if ( ! $ query ) {
26- $ query = new \Spameri \ElasticQuery \Query \QueryCollection ();
27- }
28-
29- if ( ! $ filter ) {
30- $ filter = new \Spameri \ElasticQuery \Filter \FilterCollection ();
31- }
32-
3344 $ this ->query = $ query ;
3445 $ this ->filter = $ filter ;
46+ $ this ->sort = $ sort ;
47+ $ this ->aggregation = $ aggregation ;
48+ $ this ->from = $ from ;
49+ $ this ->size = $ size ;
3550 }
3651
3752
@@ -49,12 +64,31 @@ public function filter() : \Spameri\ElasticQuery\Filter\FilterCollection
4964
5065 public function toArray () : array
5166 {
52- $ array = [
53- 'query ' => $ this ->query ->toArray (),
54- 'filter ' => $ this ->filter ->toArray (),
55- 'sort ' ,
56- 'aggregation ' ,
57- ];
67+ $ array = [];
68+
69+ if ($ this ->query ) {
70+ $ array ['query ' ] = $ this ->query ->toArray ();
71+ }
72+
73+ if ($ this ->filter ) {
74+ $ array ['filter ' ] = $ this ->filter ->toArray ();
75+ }
76+
77+ if ($ this ->sort ) {
78+ $ array ['sort ' ] = $ this ->sort ;
79+ }
80+
81+ if ($ this ->aggregation ) {
82+ $ array ['aggregation ' ] = $ this ->aggregation ;
83+ }
84+
85+ if ($ this ->size ) {
86+ $ array ['size ' ] = $ this ->size ;
87+ }
88+
89+ if ($ this ->from ) {
90+ $ array ['from ' ] = $ this ->from ;
91+ }
5892
5993 return $ array ;
6094 }
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ class Match extends AbstractLeafQuery
4242
4343 public function __construct (
4444 string $ field ,
45- string $ query ,
45+ $ query ,
4646 float $ boost = 1.0 ,
4747 string $ operator = \Spameri \ElasticQuery \Query \Match \Operator::OR ,
4848 ?int $ slop = NULL ,
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ class Term extends AbstractLeafQuery
2222
2323 public function __construct (
2424 string $ field ,
25- string $ query ,
25+ $ query ,
2626 float $ boost = 1.0
2727 )
2828 {
You can’t perform that action at this time.
0 commit comments