Skip to content

Commit d74bcb9

Browse files
committed
Change readme
1 parent 5024cab commit d74bcb9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class ProductSpecification extends CompositeSpecification
3737
AllowedAggregate::minmax('rating')
3838
]);
3939

40+
$this->allowedFacets([
41+
'package'
42+
]);
43+
4044
$this->whereNotNull('package');
4145

4246
$this->nested('offers', function (Specification $spec) {
@@ -50,6 +54,10 @@ class ProductSpecification extends CompositeSpecification
5054
$spec->allowedSorts([
5155
AllowedSort::field('price')->byMin()
5256
]);
57+
58+
$spec->allowedFacets([
59+
AllowedFacet::terms('seller_id')
60+
]);
5361
});
5462
}
5563
}
@@ -74,6 +82,15 @@ Here are examples of queries for this specification.
7482
}
7583
}
7684
```
85+
```json
86+
{
87+
"facet": ["seller_id", "package"],
88+
"filter": {
89+
"package": "bottle",
90+
"seller_id": [10, 20, 50, 90]
91+
}
92+
}
93+
```
7794

7895
The `nested` method adds specifications for nested documents. The names of filters, aggregates, and sorts are exported
7996
from them to the global scope without adding any prefixes. It is acceptable to have the same names for filters, but not
@@ -158,6 +175,25 @@ AllowedAggregate::minmax('name', 'field'); // Get min and max attribute values
158175

159176
Aggregates from nested specifications are added to the Elasticsearch query with all constraints and active filters.
160177

178+
You can use the `allowedFacets` method to define facets. Each facet requires an aggregate and one or
179+
more filters. You can use both the existing aggregate
180+
181+
```php
182+
AllowedFacet::fromAggregate('name', 'filter');
183+
```
184+
185+
and the aggregate created by the facet itself
186+
187+
```php
188+
AllowedFacet::terms('name', 'filter');
189+
AllowedFacet::minmax('name', ['filter1', 'filter2']);
190+
```
191+
192+
Filters are registered in the specification separately. Only their names are passed to facet creation methods.
193+
194+
During the calculation of the available values for each facet, all set filters are applied except those associated with
195+
this facet.
196+
161197
## Search for documents
162198

163199
```php

0 commit comments

Comments
 (0)