Skip to content

Commit 5ceddad

Browse files
committed
Added phrase prefix query
1 parent e9e0a5c commit 5ceddad

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/Query/PhrasePrefix.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\ElasticQuery\Query;
4+
5+
class PhrasePrefix implements \Spameri\ElasticQuery\Query\LeafQueryInterface
6+
{
7+
8+
private string $field;
9+
10+
private string $queryString;
11+
12+
private int $boost;
13+
14+
private int $slop;
15+
16+
17+
public function __construct(
18+
string $field,
19+
string $queryString,
20+
int $boost = 1,
21+
int $slop = 1
22+
) {
23+
$this->field = $field;
24+
$this->queryString = $queryString;
25+
$this->boost = $boost;
26+
$this->slop = $slop;
27+
}
28+
29+
30+
public function key(): string
31+
{
32+
return 'phrase_prefix_' . $this->field . '_' . $this->queryString;
33+
}
34+
35+
36+
public function toArray(): array
37+
{
38+
return [
39+
'match_phrase_prefix' => [
40+
$this->field => [
41+
'query' => $this->queryString,
42+
'boost' => $this->boost,
43+
'slop' => $this->slop,
44+
],
45+
],
46+
];
47+
}
48+
49+
}

0 commit comments

Comments
 (0)