Skip to content

Commit 38b5c72

Browse files
committed
add params, fields and highlight to QueryBuilder
1 parent e1ab636 commit 38b5c72

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

src/QueryBuilder.php

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ class QueryBuilder
2525

2626
private ?QueryInterface $query = null;
2727

28+
private ?array $fields = null;
29+
30+
private ?array $highlight = null;
31+
2832
private ?QueryInterface $postFilter = null;
2933

34+
private array $params = [];
35+
3036
public function setSource(array|bool|string|null $source): self
3137
{
3238
$this->source = $source;
@@ -69,11 +75,33 @@ public function setPostFilter(QueryInterface $query): self
6975
return $this;
7076
}
7177

78+
public function setFields(?array $fields): self
79+
{
80+
$this->fields = $fields;
81+
82+
return $this;
83+
}
84+
85+
public function setHighlight(?array $highlight): self
86+
{
87+
$this->highlight = $highlight;
88+
89+
return $this;
90+
}
91+
92+
public function setParams(array $params): self
93+
{
94+
$this->params = $params;
95+
96+
return $this;
97+
}
98+
7299
public function build(): array
73100
{
74-
$query = [
75-
'body' => [],
76-
];
101+
$query = $this->params;
102+
if (!isset($query['body'])) {
103+
$query['body'] = [];
104+
}
77105

78106
if (null !== $this->index) {
79107
$query['index'] = $this->index;
@@ -99,6 +127,14 @@ public function build(): array
99127
$query['body']['post_filter'] = $this->postFilter->build();
100128
}
101129

130+
if (null !== $this->fields) {
131+
$query['body']['fields'] = $this->fields;
132+
}
133+
134+
if (null !== $this->highlight) {
135+
$query['body']['highlight'] = $this->highlight;
136+
}
137+
102138
$this->buildSortTo($query['body'])
103139
->buildAggregationsTo($query['body'])
104140
->buildCollapseTo($query['body']);

0 commit comments

Comments
 (0)