AggregationDTO.php 682 B

1234567891011121314151617181920212223242526
  1. <?php
  2. namespace App\DTO\Search;
  3. /**
  4. * 通用聚合结果DTO
  5. * 用于处理所有结构相同的聚合桶数据
  6. */
  7. class AggregationDTO
  8. {
  9. public function __construct(
  10. public int $doc_count_error_upper_bound,
  11. public int $sum_other_doc_count,
  12. /** @var BucketDTO[] */
  13. public array $buckets,
  14. ) {}
  15. public static function fromArray(array $data): self
  16. {
  17. return new self(
  18. doc_count_error_upper_bound: $data['doc_count_error_upper_bound'],
  19. sum_other_doc_count: $data['sum_other_doc_count'],
  20. buckets: array_map(fn($bucket) => BucketDTO::fromArray($bucket), $data['buckets']),
  21. );
  22. }
  23. }