| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- namespace Elastica\Multi;
- use Elastica\Response;
- /**
- * Elastica multi search result set
- * List of result sets for each search request.
- *
- * @author munkie
- */
- class ResultSet implements \Iterator, \ArrayAccess, \Countable
- {
- /**
- * Result Sets.
- *
- * @var array|\Elastica\ResultSet[] Result Sets
- */
- protected $_resultSets = [];
- /**
- * Current position.
- *
- * @var int Current position
- */
- protected $_position = 0;
- /**
- * Response.
- *
- * @var \Elastica\Response Response object
- */
- protected $_response;
- /**
- * Constructs ResultSet object.
- *
- * @param \Elastica\Response $response
- * @param \Elastica\ResultSet[] $resultSets
- */
- public function __construct(Response $response, $resultSets)
- {
- $this->_response = $response;
- $this->_resultSets = $resultSets;
- }
- /**
- * @return array|\Elastica\ResultSet[]
- */
- public function getResultSets()
- {
- return $this->_resultSets;
- }
- /**
- * Returns response object.
- *
- * @return \Elastica\Response Response object
- */
- public function getResponse()
- {
- return $this->_response;
- }
- /**
- * There is at least one result set with error.
- *
- * @return bool
- */
- public function hasError()
- {
- foreach ($this->getResultSets() as $resultSet) {
- if ($resultSet->getResponse()->hasError()) {
- return true;
- }
- }
- return false;
- }
- /**
- * @return \Elastica\ResultSet
- */
- public function current()
- {
- return $this->_resultSets[$this->key()];
- }
- public function next()
- {
- ++$this->_position;
- }
- /**
- * @return int
- */
- public function key()
- {
- return $this->_position;
- }
- /**
- * @return bool
- */
- public function valid()
- {
- return isset($this->_resultSets[$this->key()]);
- }
- public function rewind()
- {
- $this->_position = 0;
- }
- /**
- * @return int
- */
- public function count()
- {
- return count($this->_resultSets);
- }
- /**
- * @param string|int $offset
- *
- * @return bool true on success or false on failure
- */
- public function offsetExists($offset)
- {
- return isset($this->_resultSets[$offset]);
- }
- /**
- * @param mixed $offset
- *
- * @return mixed can return all value types
- */
- public function offsetGet($offset)
- {
- return $this->_resultSets[$offset] ?? null;
- }
- /**
- * @param mixed $offset
- * @param mixed $value
- */
- public function offsetSet($offset, $value)
- {
- if (is_null($offset)) {
- $this->_resultSets[] = $value;
- } else {
- $this->_resultSets[$offset] = $value;
- }
- }
- /**
- * @param mixed $offset
- */
- public function offsetUnset($offset)
- {
- unset($this->_resultSets[$offset]);
- }
- }
|