55use Closure ;
66use Ensi \LaravelElasticQuery \Contracts \BoolQuery ;
77use Ensi \LaravelElasticQuerySpecification \Agregating \AllowedAggregate ;
8+ use Ensi \LaravelElasticQuerySpecification \Collapsing \AllowedCollapse ;
89use Ensi \LaravelElasticQuerySpecification \Contracts \Constraint ;
910use Ensi \LaravelElasticQuerySpecification \Exceptions \ComponentExistsException ;
1011use Ensi \LaravelElasticQuerySpecification \Faceting \AllowedFacet ;
@@ -30,6 +31,9 @@ class Specification
3031 /** @var array|AllowedFacet[] */
3132 protected array $ facets = [];
3233
34+ /** @var array|AllowedCollapse[] */
35+ protected array $ collapses = [];
36+
3337 public static function new (): static
3438 {
3539 return new static ();
@@ -194,6 +198,27 @@ public function activeFacets(): Collection
194198 }
195199 //endregion
196200
201+ //region Collapse
202+ public function allowedCollapses (array $ collapses ): static
203+ {
204+ foreach ($ collapses as $ collapse ) {
205+ $ collapse = AllowedCollapse::wrap ($ collapse );
206+
207+ $ this ->addComponent ($ this ->collapses , $ collapse ->name (), $ collapse , 'collapse ' );
208+ }
209+
210+ return $ this ;
211+ }
212+
213+ /**
214+ * @return Collection<int,AllowedCollapse>
215+ */
216+ public function collapses (): Collection
217+ {
218+ return new Collection ($ this ->collapses );
219+ }
220+ //endregion
221+
197222 private function addComponent (array &$ target , string $ name , mixed $ component , string $ type ): void
198223 {
199224 if (array_key_exists ($ name , $ target )) {
0 commit comments