Skip to content

Commit 1bd21bf

Browse files
committed
Use construction parameter instead of trait
1 parent 4337d43 commit 1bd21bf

16 files changed

+176
-119
lines changed

src/Features/HasDefaultOptions.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Query/AbstractMatchQuery.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ abstract class AbstractMatchQuery implements QueryInterface
1414
public function __construct(
1515
string $field,
1616
protected string $query,
17-
protected ?string $analyzer = null
17+
protected ?string $analyzer = null,
18+
protected array $params = [],
1819
) {
1920
$this->field = $field;
2021
}
@@ -37,11 +38,10 @@ public function build(): array
3738
{
3839
$queryName = $this->getQueryName();
3940

40-
$query = [
41-
$queryName => [
42-
$this->field => [
43-
'query' => $this->query,
44-
],
41+
$query = $this->params;
42+
$query[$queryName] = [
43+
$this->field => [
44+
'query' => $this->query,
4545
],
4646
];
4747

src/Query/BoolQuery.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function __construct(
2020
private array $mustNot = [],
2121
private array $should = [],
2222
private array $filter = [],
23+
private array $params = [],
2324
) {
2425
}
2526

@@ -77,7 +78,7 @@ public function isEmpty(): bool
7778

7879
public function build(): array
7980
{
80-
$query = [];
81+
$query = $this->params;
8182

8283
$this
8384
->buildQueries($query, 'should', $this->should)

src/Query/GeoDistanceQuery.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class GeoDistanceQuery implements QueryInterface
1717
public function __construct(
1818
private string $distance,
1919
string $field,
20-
private array $position
20+
private array $position,
21+
private array $params = [],
2122
) {
2223
$this->field = $field;
2324
}
@@ -38,14 +39,15 @@ public function setPosition(array $position): self
3839

3940
public function build(): array
4041
{
41-
return [
42-
'geo_distance' => [
43-
'distance' => $this->distance,
44-
$this->field => [
45-
'lat' => $this->position[0],
46-
'lon' => $this->position[1],
47-
],
42+
$build = $this->params;
43+
$build['geo_distance'] = [
44+
'distance' => $this->distance,
45+
$this->field => [
46+
'lat' => $this->position[0],
47+
'lon' => $this->position[1],
4848
],
4949
];
50+
51+
return $build;
5052
}
5153
}

src/Query/GeoShapeQuery.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class GeoShapeQuery implements QueryInterface
1616
public function __construct(
1717
private string $field,
1818
private string $type,
19-
private array $coordinates
19+
private array $coordinates,
20+
private array $params = [],
2021
) {
2122
}
2223

@@ -50,16 +51,17 @@ public function setRelation(string $relation): self
5051

5152
public function build(): array
5253
{
53-
return [
54-
'geo_shape' => [
55-
$this->field => [
56-
'shape' => [
57-
'type' => $this->type,
58-
'coordinates' => $this->coordinates,
59-
],
60-
'relation' => $this->relation,
54+
$build = $this->params;
55+
$build['geo_shape'] = [
56+
$this->field => [
57+
'shape' => [
58+
'type' => $this->type,
59+
'coordinates' => $this->coordinates,
6160
],
61+
'relation' => $this->relation,
6262
],
6363
];
64+
65+
return $build;
6466
}
6567
}

src/Query/MatchQuery.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ public function __construct(
1717
string $query,
1818
?string $analyzer = null,
1919
?string $operator = null,
20-
?string $minimumShouldMatch = null
20+
?string $minimumShouldMatch = null,
21+
array $params = [],
2122
) {
22-
parent::__construct($field, $query, $analyzer);
23+
parent::__construct($field, $query, $analyzer, $params);
2324

2425
$this->operator = $operator;
2526
$this->minimumShouldMatch = $minimumShouldMatch;

src/Query/MultiMatchQuery.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public function __construct(
2525
protected ?string $fuzziness = null,
2626
?string $operator = null,
2727
?float $boost = null,
28-
?string $minimumShouldMatch = null
28+
?string $minimumShouldMatch = null,
29+
protected array $params = [],
2930
) {
3031
$this->operator = $operator;
3132
$this->boost = $boost;
@@ -79,8 +80,9 @@ public function build(): array
7980
$this->buildBoostTo($data);
8081
$this->buildMinimumShouldMatchTo($data);
8182

82-
return [
83-
'multi_match' => $data,
84-
];
83+
$build = $this->params;
84+
$build['multi_match'] = $data;
85+
86+
return $build;
8587
}
8688
}

src/Query/NestedQuery.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class NestedQuery implements QueryInterface
1010
{
1111
public function __construct(
1212
protected ?string $path,
13-
protected QueryInterface $query
13+
protected QueryInterface $query,
14+
protected array $params = [],
1415
) {
1516
}
1617

@@ -30,11 +31,12 @@ public function setQuery(QueryInterface $query): self
3031

3132
public function build(): array
3233
{
33-
return [
34-
'nested' => [
35-
'path' => $this->path,
36-
'query' => $this->query->build(),
37-
],
34+
$build = $this->params;
35+
$build['nested'] = [
36+
'path' => $this->path,
37+
'query' => $this->query->build(),
3838
];
39+
40+
return $build;
3941
}
4042
}

src/Query/PrefixQuery.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public function __construct(
2222
string $field,
2323
protected string $value,
2424
?string $rewrite = null,
25-
?bool $caseInsensitive = null
25+
?bool $caseInsensitive = null,
26+
protected array $params = [],
2627
) {
2728
$this->field = $field;
2829
$this->rewrite = $rewrite;
@@ -38,9 +39,8 @@ public function setValue(string $value): self
3839

3940
public function build(): array
4041
{
41-
$build = [
42-
'value' => $this->value,
43-
];
42+
$build = $this->params;
43+
$build['value'] = $this->value;
4444

4545
$this->buildRewriteTo($build);
4646
$this->buildCaseInsensitiveTo($build);

0 commit comments

Comments
 (0)