From 15e69f7b20b6596b9148030acce5b59993b95a45 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 18 Dec 2015 06:00:00 +0100 Subject: Update to MediaWiki 1.25.4 --- .../elastica/lib/Elastica/Multi/ResultSet.php | 208 +++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 vendor/ruflin/elastica/lib/Elastica/Multi/ResultSet.php (limited to 'vendor/ruflin/elastica/lib/Elastica/Multi/ResultSet.php') diff --git a/vendor/ruflin/elastica/lib/Elastica/Multi/ResultSet.php b/vendor/ruflin/elastica/lib/Elastica/Multi/ResultSet.php new file mode 100644 index 00000000..a0df5785 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Multi/ResultSet.php @@ -0,0 +1,208 @@ +rewind(); + $this->_init($response, $searches); + } + + /** + * @param \Elastica\Response $response + * @param array|\Elastica\Search[] $searches + * @throws \Elastica\Exception\InvalidException + */ + protected function _init(Response $response, array $searches) + { + $this->_response = $response; + $responseData = $response->getData(); + + if (isset($responseData['responses']) && is_array($responseData['responses'])) { + reset($searches); + foreach ($responseData['responses'] as $key => $responseData) { + $currentSearch = each($searches); + + if ($currentSearch === false) { + throw new InvalidException('No result found for search #' . $key); + } elseif (!$currentSearch['value'] instanceof BaseSearch) { + throw new InvalidException('Invalid object for search #' . $key . ' provided. Should be Elastica\Search'); + } + + $search = $currentSearch['value']; + $query = $search->getQuery(); + + $response = new Response($responseData); + $this->_resultSets[$currentSearch['key']] = new BaseResultSet($response, $query); + } + } + } + + /** + * @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 bool|\Elastica\ResultSet + */ + public function current() + { + if ($this->valid()) { + return $this->_resultSets[$this->key()]; + } else { + return false; + } + } + + /** + * @return void + */ + public function next() + { + $this->_position++; + } + + /** + * @return int + */ + public function key() + { + return $this->_position; + } + + /** + * @return bool + */ + public function valid() + { + return isset($this->_resultSets[$this->key()]); + } + + /** + * @return void + */ + public function rewind() + { + $this->_position = 0; + } + + /** + * @return int + */ + public function count() + { + return count($this->_resultSets); + } + + /** + * @param string|int $offset + * @return boolean 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 isset($this->_resultSets[$offset]) ? $this->_resultSets[$offset] : null; + } + + /** + * @param mixed $offset + * @param mixed $value + * @return void + */ + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->_resultSets[] = $value; + } else { + $this->_resultSets[$offset] = $value; + } + } + + /** + * @param mixed $offset + * @return void + */ + public function offsetUnset($offset) + { + unset($this->_resultSets[$offset]); + } +} -- cgit v1.2.3-54-g00ecf