QueryResponse.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Search\Response;
  7. use Magento\Framework\Api\Search\AggregationInterface;
  8. use Magento\Framework\Api\Search\Document;
  9. use Magento\Framework\Search\ResponseInterface;
  10. /**
  11. * Search Response
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class QueryResponse implements ResponseInterface
  16. {
  17. /**
  18. * Document Collection
  19. *
  20. * @var Document[]
  21. */
  22. protected $documents;
  23. /**
  24. * Aggregation Collection
  25. *
  26. * @var AggregationInterface
  27. */
  28. protected $aggregations;
  29. /**
  30. * @param Document[] $documents
  31. * @param AggregationInterface $aggregations
  32. */
  33. public function __construct(array $documents, AggregationInterface $aggregations)
  34. {
  35. $this->documents = $documents;
  36. $this->aggregations = $aggregations;
  37. }
  38. /**
  39. * Countable: return count of fields in document
  40. * @return int
  41. */
  42. public function count()
  43. {
  44. return count($this->documents);
  45. }
  46. /**
  47. * Implementation of \IteratorAggregate::getIterator()
  48. *
  49. * @return \ArrayIterator
  50. */
  51. public function getIterator()
  52. {
  53. return new \ArrayIterator($this->documents);
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function getAggregations()
  59. {
  60. return $this->aggregations;
  61. }
  62. }