Skip to content

Commit 81b494d

Browse files
committed
Added slop and type to Match query
1 parent 63822cf commit 81b494d

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

src/Query/Match.php

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,44 @@
66
/**
77
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
88
*/
9-
class Match implements LeafQueryInterface
9+
class Match implements \Spameri\ElasticQuery\Query\LeafQueryInterface
1010
{
1111

12-
/**
13-
* @var string
14-
*/
15-
private $field;
12+
private string $field;
1613

1714
/**
1815
* @var string|int|bool|null
1916
*/
2017
private $query;
2118

22-
/**
23-
* @var string
24-
*/
25-
private $operator;
19+
private string $operator;
2620

27-
/**
28-
* @var null|\Spameri\ElasticQuery\Query\Match\Fuzziness
29-
*/
30-
private $fuzziness;
21+
private ?\Spameri\ElasticQuery\Query\Match\Fuzziness $fuzziness;
3122

32-
/**
33-
* @var float
34-
*/
35-
private $boost;
23+
private float $boost;
3624

37-
/**
38-
* @var null|string
39-
*/
40-
private $analyzer;
25+
private ?string $analyzer;
4126

42-
/**
43-
* @var int|null
44-
*/
45-
private $minimumShouldMatch;
27+
private ?int $minimumShouldMatch;
28+
29+
private int $slop;
30+
31+
private ?string $type;
4632

4733

4834
/**
4935
* @param string|int|bool|null $query
5036
*/
5137
public function __construct(
52-
string $field
53-
, $query
54-
, float $boost = 1.0
55-
, string $operator = \Spameri\ElasticQuery\Query\Match\Operator::OR
56-
, ?\Spameri\ElasticQuery\Query\Match\Fuzziness $fuzziness = NULL
57-
, ?string $analyzer = NULL
58-
, ?int $minimumShouldMatch = NULL
38+
string $field,
39+
$query,
40+
float $boost = 1.0,
41+
int $slop = 1,
42+
?\Spameri\ElasticQuery\Query\Match\Fuzziness $fuzziness = NULL,
43+
?string $type = NULL,
44+
?int $minimumShouldMatch = NULL,
45+
string $operator = \Spameri\ElasticQuery\Query\Match\Operator::OR,
46+
?string $analyzer = NULL
5947
)
6048
{
6149
if ( ! \in_array($operator, \Spameri\ElasticQuery\Query\Match\Operator::OPERATORS, TRUE)) {
@@ -71,6 +59,8 @@ public function __construct(
7159
$this->boost = $boost;
7260
$this->analyzer = $analyzer;
7361
$this->minimumShouldMatch = $minimumShouldMatch;
62+
$this->slop = $slop;
63+
$this->type = $type;
7464
}
7565

7666

@@ -87,10 +77,15 @@ public function toArray(): array
8777
$this->field => [
8878
'query' => $this->query,
8979
'boost' => $this->boost,
80+
'slop' => $this->slop,
9081
],
9182
],
9283
];
9384

85+
if ($this->type) {
86+
$array['match'][$this->field]['type'] = $this->type;
87+
}
88+
9489
if ($this->operator) {
9590
$array['match'][$this->field]['operator'] = $this->operator;
9691
}

0 commit comments

Comments
 (0)