Skip to content

Commit

Permalink
Moved ResultSet creation to a static factory method
Browse files Browse the repository at this point in the history
  • Loading branch information
merk committed Oct 5, 2014
1 parent ffbfa5d commit 1c82738
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changes.txt
@@ -1,5 +1,8 @@
CHANGES

2014-10-05
- ResultSet creation moved to static ResultSet::create() method #690

2014-10-04
- Release v1.3.4.0
- Update to elasticsearch 1.3.4 #691
Expand Down
32 changes: 32 additions & 0 deletions lib/Elastica/ResultSet.php
Expand Up @@ -15,6 +15,13 @@
*/
class ResultSet implements \Iterator, \Countable, \ArrayAccess
{
/**
* Class for the static create method to use.
*
* @var string
*/
protected static $_class = 'Elastica\\ResultSet';

/**
* Results
*
Expand Down Expand Up @@ -76,6 +83,31 @@ public function __construct(Response $response, Query $query)
$this->_query = $query;
}

/**
* 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)
*
Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Search.php
Expand Up @@ -436,7 +436,7 @@ public function search($query = '', $options = null)
$params
);

return new ResultSet($response, $query);
return ResultSet::create($response, $query);
}

/**
Expand All @@ -458,7 +458,7 @@ public function count($query = '', $fullResult = false)
$query->toArray(),
array(self::OPTION_SEARCH_TYPE => self::OPTION_SEARCH_TYPE_COUNT)
);
$resultSet = new ResultSet($response, $query);
$resultSet = ResultSet::create($response, $query);

return $fullResult ? $resultSet : $resultSet->getTotalHits();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Type.php
Expand Up @@ -492,7 +492,7 @@ public function moreLikeThis(Document $doc, $params = array(), $query = array())

$response = $this->request($path, Request::GET, $query->toArray(), $params);

return new ResultSet($response, $query);
return ResultSet::create($response, $query);
}

/**
Expand Down

0 comments on commit 1c82738

Please sign in to comment.