Skip to content

Commit 74580e1

Browse files
committed
Clean README
1 parent 803b3f0 commit 74580e1

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

README.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Installation
1313
------------
1414

1515
```bash
16-
composer require erichard/elasticsearch-query-builder
16+
composer require erichard/elasticsearch-query-builder "^3.0@beta"
1717
```
1818

1919
Usage
@@ -28,7 +28,6 @@ use Erichard\ElasticQueryBuilder\Filter\Filter;
2828
$query = new QueryBuilder();
2929

3030
$query
31-
->setType('my_type')
3231
->setIndex('app')
3332
->setSize(10)
3433
;
@@ -48,20 +47,34 @@ $query->addFilter($boolFilter);
4847
$results = $client->search($query->build());
4948
```
5049

51-
with PHP 8.1 you can do this:
50+
with PHP 8.1 you can use named arguments like this:
5251

5352
```php
54-
new BoolQuery(should: [
53+
$query = new BoolQuery(must: [
5554
new RangeQuery(
56-
field: PriceTermsIndex::PREFIX_OPTION . OptionIds::PERSONS_MAX,
57-
gte: $this->roomCount
55+
field: 'price',
56+
gte: 100
5857
),
5958
new RangeQuery(
60-
field: PriceTermsIndex::PREFIX_OPTION . OptionIds::PERSONS_MAX,
61-
gte: $this->roomCount
59+
field: 'stock',
60+
gte: 10
6261
),
63-
])
64-
]
62+
]);
63+
```
64+
65+
or with the factory
66+
67+
```php
68+
$query = Query::bool(must: [
69+
Query::range(
70+
field: 'price',
71+
gte: 100
72+
),
73+
Query::range(
74+
field: 'stock',
75+
gte: 10
76+
),
77+
]);
6578
```
6679

6780
Contribution

src/Query/Query.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ public static function bool(
4141
return new BoolQuery($must, $mustNot, $should, $filter);
4242
}
4343

44-
public static function range(string $field): RangeQuery
45-
{
46-
return new RangeQuery($field);
44+
public static function range(
45+
string $field,
46+
int|float|string|null $lt = null,
47+
int|float|string|null $gt = null,
48+
int|float|string|null $lte = null,
49+
int|float|string|null $gte = null
50+
): RangeQuery {
51+
return new RangeQuery($field, $lt, $gt, $lte, $gte);
4752
}
4853

4954
public static function nested(string $field, QueryInterface $query): NestedQuery

0 commit comments

Comments
 (0)