Skip to content

Commit ac875a5

Browse files
authored
Merge pull request #15 from xsuchy09/feature/parameters
New parameters, some fixes.
2 parents 74580e1 + 5fd20fc commit ac875a5

26 files changed

+454
-56
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor
22
composer.lock
3-
.phpunit.result.cache
3+
.phpunit.result.cache
4+
.editorconfig

phpstan.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ parameters:
1212
- src
1313
- tests
1414

15-
# The level 8 is the highest level
16-
level: 8
15+
# The level 9 is the highest level
16+
level: 9
1717

1818
# it is impossible to map build()
1919
checkMissingIterableValueType: false

src/Features/HasBoost.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Erichard\ElasticQueryBuilder\Features;
6+
7+
trait HasBoost
8+
{
9+
protected ?float $boost = null;
10+
11+
public function setBoost(?float $boost): self
12+
{
13+
$this->boost = $boost;
14+
15+
return $this;
16+
}
17+
18+
public function buildBoostTo(array &$array): self
19+
{
20+
if (null === $this->boost) {
21+
return $this;
22+
}
23+
24+
$array['boost'] = $this->boost;
25+
26+
return $this;
27+
}
28+
29+
public function getBoost(): ?float
30+
{
31+
return $this->boost;
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Erichard\ElasticQueryBuilder\Features;
6+
7+
trait HasCaseInsensitive
8+
{
9+
protected ?bool $caseInsensitive = null;
10+
11+
public function setCaseInsensitive(?bool $caseInsensitive): self
12+
{
13+
$this->caseInsensitive = $caseInsensitive;
14+
15+
return $this;
16+
}
17+
18+
public function buildCaseInsensitiveTo(array &$array): self
19+
{
20+
if (null === $this->caseInsensitive) {
21+
return $this;
22+
}
23+
24+
$array['case_insensitive'] = $this->caseInsensitive;
25+
26+
return $this;
27+
}
28+
29+
public function getCaseInsensitive(): ?bool
30+
{
31+
return $this->caseInsensitive;
32+
}
33+
}

src/Features/HasFormat.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Erichard\ElasticQueryBuilder\Features;
6+
7+
trait HasFormat
8+
{
9+
protected ?string $format = null;
10+
11+
public function setFormat(?string $format): self
12+
{
13+
$this->format = $format;
14+
15+
return $this;
16+
}
17+
18+
public function buildFormatTo(array &$array): self
19+
{
20+
if (null === $this->format) {
21+
return $this;
22+
}
23+
24+
$array['format'] = $this->format;
25+
26+
return $this;
27+
}
28+
29+
public function getFormat(): ?string
30+
{
31+
return $this->format;
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Erichard\ElasticQueryBuilder\Features;
6+
7+
trait HasMinimumShouldMatch
8+
{
9+
protected ?string $minimumShouldMatch = null;
10+
11+
public function setMinimumShouldMatch(?string $minimumShouldMatch): self
12+
{
13+
$this->minimumShouldMatch = $minimumShouldMatch;
14+
15+
return $this;
16+
}
17+
18+
public function buildMinimumShouldMatchTo(array &$array): self
19+
{
20+
if (null === $this->minimumShouldMatch) {
21+
return $this;
22+
}
23+
24+
$array['minimum_should_match'] = $this->minimumShouldMatch;
25+
26+
return $this;
27+
}
28+
29+
public function getMinimumShouldMatch(): ?string
30+
{
31+
return $this->minimumShouldMatch;
32+
}
33+
}

src/Features/HasRewrite.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Erichard\ElasticQueryBuilder\Features;
6+
7+
trait HasRewrite
8+
{
9+
protected ?string $rewrite = null;
10+
11+
public function setRewrite(?string $rewrite): self
12+
{
13+
$this->rewrite = $rewrite;
14+
15+
return $this;
16+
}
17+
18+
public function buildRewriteTo(array &$array): self
19+
{
20+
if (null === $this->rewrite) {
21+
return $this;
22+
}
23+
24+
$array['rewrite'] = $this->rewrite;
25+
26+
return $this;
27+
}
28+
29+
public function getRewrite(): ?string
30+
{
31+
return $this->rewrite;
32+
}
33+
}

src/Features/HasSorting.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function addSort(string $field, string|array $config = SortDirections::AS
3232
*/
3333
protected function buildSortTo(array &$toArray): self
3434
{
35-
if (false === empty($this->sort)) {
35+
if (empty($this->sort) === false) {
3636
foreach ($this->sort as $sort => $config) {
3737
$toArray['sort'][$sort] = $config;
3838
}

src/Options/Collapse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function build(): array
4848
$result['max_concurrent_group_searches'] = $this->maxConcurrentSearchers;
4949
}
5050

51-
if (false === empty($this->innerHits)) {
51+
if (empty($this->innerHits) === false) {
5252
$result['inner_hits'] = array_map(fn (InnerHit $hit) => $hit->build(), $this->innerHits);
5353
}
5454

src/Query/MatchQuery.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,39 @@
44

55
namespace Erichard\ElasticQueryBuilder\Query;
66

7+
use Erichard\ElasticQueryBuilder\Features\HasMinimumShouldMatch;
8+
use Erichard\ElasticQueryBuilder\Features\HasOperator;
9+
710
class MatchQuery extends AbstractMatchQuery
811
{
12+
use HasOperator;
13+
use HasMinimumShouldMatch;
14+
15+
public function __construct(
16+
string $field,
17+
string $query,
18+
?string $analyzer = null,
19+
?string $operator = null,
20+
?string $minimumShouldMatch = null
21+
) {
22+
parent::__construct($field, $query, $analyzer);
23+
24+
$this->operator = $operator;
25+
$this->minimumShouldMatch = $minimumShouldMatch;
26+
}
27+
928
public function getQueryName(): string
1029
{
1130
return 'match';
1231
}
32+
33+
public function build(): array
34+
{
35+
$build = parent::build();
36+
37+
$this->buildOperatorTo($build[$this->getQueryName()][$this->field]);
38+
$this->buildMinimumShouldMatchTo($build[$this->getQueryName()][$this->field]);
39+
40+
return $build;
41+
}
1342
}

0 commit comments

Comments
 (0)