Skip to content

Commit 4f1cfe6

Browse files
Add PrefixQuery
1 parent 6aba5ff commit 4f1cfe6

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `elasticsearch-query-builder` will be documented in this file.
44

5+
## 1.3.0 - 2021-08-06
6+
7+
- add `PrefixQuery`
8+
59
## 1.2.2 - 2021-07-29
610

711
- remove debug statements (again :facepalm:)

src/Queries/PrefixQuery.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Spatie\ElasticsearchQueryBuilder\Queries;
4+
5+
class PrefixQuery implements Query
6+
{
7+
public static function create(
8+
string $field,
9+
string | int $query
10+
): self {
11+
return new self($field, $query);
12+
}
13+
14+
public function __construct(
15+
protected string $field,
16+
protected string | int $query
17+
) {
18+
}
19+
20+
public function toArray(): array
21+
{
22+
return [
23+
'prefix' => [
24+
$this->field => [
25+
'value' => $this->query,
26+
],
27+
],
28+
];
29+
}
30+
}

0 commit comments

Comments
 (0)