diff options
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/ResultSet.php')
-rw-r--r-- | vendor/ruflin/elastica/lib/Elastica/ResultSet.php | 172 |
1 files changed, 111 insertions, 61 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/ResultSet.php b/vendor/ruflin/elastica/lib/Elastica/ResultSet.php index 3bb94fb0..ae4141b9 100644 --- a/vendor/ruflin/elastica/lib/Elastica/ResultSet.php +++ b/vendor/ruflin/elastica/lib/Elastica/ResultSet.php @@ -1,43 +1,48 @@ <?php - namespace Elastica; + use Elastica\Exception\InvalidException; /** - * Elastica result set + * Elastica result set. * * List of all hits that are returned for a search on elasticsearch * Result set implements iterator * - * @category Xodoa - * @package Elastica * @author Nicolas Ruflin <spam@ruflin.com> */ class ResultSet implements \Iterator, \Countable, \ArrayAccess { /** - * Results + * Class for the static create method to use. + * + * @var string + */ + protected static $_class = 'Elastica\\ResultSet'; + + /** + * Results. * * @var array Results */ protected $_results = array(); /** - * Current position + * Current position. * * @var int Current position */ protected $_position = 0; /** - * Response + * Response. * * @var \Elastica\Response Response object */ protected $_response = null; /** - * Query + * Query. * * @var \Elastica\Query Query object */ @@ -49,7 +54,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess protected $_took = 0; /** - * @var boolean + * @var bool */ protected $_timedOut = false; @@ -64,7 +69,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess protected $_maxScore = 0; /** - * Constructs ResultSet object + * Constructs ResultSet object. * * @param \Elastica\Response $response Response object * @param \Elastica\Query $query Query object @@ -77,7 +82,33 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Loads all data into the results object (initialisation) + * Creates a new ResultSet object. Can be configured to return a different + * implementation of the ResultSet class. + * + * @param Response $response + * @param Query $query + * + * @return ResultSet + */ + public static function create(Response $response, Query $query) + { + $class = static::$_class; + + return new $class($response, $query); + } + + /** + * Sets the class to be used for the static create method. + * + * @param string $class + */ + public static function setClass($class) + { + static::$_class = $class; + } + + /** + * Loads all data into the results object (initialisation). * * @param \Elastica\Response $response Response object */ @@ -97,7 +128,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Returns all results + * Returns all results. * * @return Result[] Results */ @@ -107,29 +138,35 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Returns true if the response contains suggestion results; false otherwise + * Returns true if the response contains suggestion results; false otherwise. + * * @return bool */ - public function hasSuggests(){ + public function hasSuggests() + { $data = $this->_response->getData(); + return isset($data['suggest']); } /** - * Return all suggests - * - * @return array suggest results - */ - public function getSuggests() + * Return all suggests. + * + * @return array suggest results + */ + public function getSuggests() { $data = $this->_response->getData(); + return isset($data['suggest']) ? $data['suggest'] : array(); } /** - * Returns whether facets exist + * Returns whether facets exist. * - * @return boolean Facet existence + * @return bool Facet existence + * + * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead. */ public function hasFacets() { @@ -139,9 +176,9 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Returns whether aggregations exist + * Returns whether aggregations exist. * - * @return boolean Aggregation existence + * @return bool Aggregation existence */ public function hasAggregations() { @@ -151,7 +188,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Returns all aggregation results + * Returns all aggregation results. * * @return array */ @@ -163,10 +200,13 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Retrieve a specific aggregation from this result set + * Retrieve a specific aggregation from this result set. + * * @param string $name the name of the desired aggregation - * @return array + * * @throws Exception\InvalidException if an aggregation by the given name cannot be found + * + * @return array */ public function getAggregation($name) { @@ -179,9 +219,11 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Returns all facets results + * Returns all facets results. * * @return array Facet results + * + * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead. */ public function getFacets() { @@ -191,7 +233,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Returns the total number of found hits + * Returns the total number of found hits. * * @return int Total hits */ @@ -201,7 +243,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Returns the max score of the results found + * Returns the max score of the results found. * * @return float Max Score */ @@ -211,27 +253,27 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Returns the total number of ms for this search to complete - * - * @return int Total time - */ + * Returns the total number of ms for this search to complete. + * + * @return int Total time + */ public function getTotalTime() { return (int) $this->_took; } /** - * Returns true iff the query has timed out - * - * @return bool Timed out - */ + * Returns true iff the query has timed out. + * + * @return bool Timed out + */ public function hasTimedOut() { return (bool) $this->_timedOut; } /** - * Returns response object + * Returns response object. * * @return \Elastica\Response Response object */ @@ -249,7 +291,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Returns size of current set + * Returns size of current set. * * @return int Size of set */ @@ -259,7 +301,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Returns size of current suggests + * Returns size of current suggests. * * @return int Size of suggests */ @@ -269,7 +311,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Returns the current object of the set + * Returns the current object of the set. * * @return \Elastica\Result|bool Set object or false if not valid (no more entries) */ @@ -283,7 +325,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Sets pointer (current) to the next item of the set + * Sets pointer (current) to the next item of the set. */ public function next() { @@ -293,7 +335,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Returns the position of the current entry + * Returns the position of the current entry. * * @return int Current position */ @@ -303,7 +345,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Check if an object exists at the current position + * Check if an object exists at the current position. * * @return bool True if object exists */ @@ -313,7 +355,7 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Resets position to 0, restarts iterator + * Resets position to 0, restarts iterator. */ public function rewind() { @@ -321,11 +363,13 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Whether a offset exists + * Whether a offset exists. + * * @link http://php.net/manual/en/arrayaccess.offsetexists.php * - * @param integer $offset - * @return boolean true on success or false on failure. + * @param int $offset + * + * @return bool true on success or false on failure. */ public function offsetExists($offset) { @@ -333,48 +377,54 @@ class ResultSet implements \Iterator, \Countable, \ArrayAccess } /** - * Offset to retrieve + * Offset to retrieve. + * * @link http://php.net/manual/en/arrayaccess.offsetget.php * - * @param integer $offset - * @throws Exception\InvalidException - * @return Result|null + * @param int $offset + * + * @throws Exception\InvalidException If offset doesn't exist + * + * @return Result|null */ public function offsetGet($offset) { if ($this->offsetExists($offset)) { return $this->_results[$offset]; } else { - throw new InvalidException("Offset does not exist."); + throw new InvalidException('Offset does not exist.'); } } /** - * Offset to set + * Offset to set. + * * @link http://php.net/manual/en/arrayaccess.offsetset.php * - * @param integer $offset - * @param Result $value - * @throws Exception\InvalidException + * @param int $offset + * @param Result $value + * + * @throws Exception\InvalidException */ public function offsetSet($offset, $value) { if (!($value instanceof Result)) { - throw new InvalidException("ResultSet is a collection of Result only."); + throw new InvalidException('ResultSet is a collection of Result only.'); } if (!isset($this->_results[$offset])) { - throw new InvalidException("Offset does not exist."); + throw new InvalidException('Offset does not exist.'); } $this->_results[$offset] = $value; } /** - * Offset to unset + * Offset to unset. + * * @link http://php.net/manual/en/arrayaccess.offsetunset.php * - * @param integer $offset + * @param int $offset */ public function offsetUnset($offset) { |