summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Search.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Search.php')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Search.php167
1 files changed, 103 insertions, 64 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Search.php b/vendor/ruflin/elastica/lib/Elastica/Search.php
index 4163a1a2..7306eb75 100644
--- a/vendor/ruflin/elastica/lib/Elastica/Search.php
+++ b/vendor/ruflin/elastica/lib/Elastica/Search.php
@@ -1,15 +1,11 @@
<?php
-
namespace Elastica;
use Elastica\Exception\InvalidException;
-use Elastica\Suggest;
/**
- * Elastica search object
+ * Elastica search object.
*
- * @category Xodoa
- * @package Elastica
* @author Nicolas Ruflin <spam@ruflin.com>
*/
class Search
@@ -26,6 +22,7 @@ class Search
const OPTION_SIZE = 'size';
const OPTION_SCROLL = 'scroll';
const OPTION_SCROLL_ID = 'scroll_id';
+ const OPTION_QUERY_CACHE = 'query_cache';
/*
* Search types
@@ -38,16 +35,17 @@ class Search
const OPTION_SEARCH_TYPE_QUERY_AND_FETCH = 'query_and_fetch';
const OPTION_SEARCH_TYPE_SUGGEST = 'suggest';
const OPTION_SEARCH_TYPE_SCROLL = 'scroll';
+ const OPTION_SEARCH_IGNORE_UNAVAILABLE = 'ignore_unavailable';
/**
- * Array of indices
+ * Array of indices.
*
* @var array
*/
protected $_indices = array();
/**
- * Array of types
+ * Array of types.
*
* @var array
*/
@@ -64,14 +62,14 @@ class Search
protected $_options = array();
/**
- * Client object
+ * Client object.
*
* @var \Elastica\Client
*/
protected $_client;
/**
- * Constructs search object
+ * Constructs search object.
*
* @param \Elastica\Client $client Client object
*/
@@ -81,11 +79,13 @@ class Search
}
/**
- * Adds a index to the list
+ * Adds a index to the list.
+ *
+ * @param \Elastica\Index|string $index Index object or string
*
- * @param \Elastica\Index|string $index Index object or string
* @throws \Elastica\Exception\InvalidException
- * @return \Elastica\Search Current object
+ *
+ * @return $this
*/
public function addIndex($index)
{
@@ -93,20 +93,21 @@ class Search
$index = $index->getName();
}
- if (!is_string($index)) {
+ if (!is_scalar($index)) {
throw new InvalidException('Invalid param type');
}
- $this->_indices[] = $index;
+ $this->_indices[] = (string) $index;
return $this;
}
/**
- * Add array of indices at once
+ * Add array of indices at once.
*
- * @param array $indices
- * @return \Elastica\Search
+ * @param array $indices
+ *
+ * @return $this
*/
public function addIndices(array $indices = array())
{
@@ -118,11 +119,13 @@ class Search
}
/**
- * Adds a type to the current search
+ * Adds a type to the current search.
+ *
+ * @param \Elastica\Type|string $type Type name or object
*
- * @param \Elastica\Type|string $type Type name or object
- * @return \Elastica\Search Search object
* @throws \Elastica\Exception\InvalidException
+ *
+ * @return $this
*/
public function addType($type)
{
@@ -140,10 +143,11 @@ class Search
}
/**
- * Add array of types
+ * Add array of types.
*
- * @param array $types
- * @return \Elastica\Search
+ * @param array $types
+ *
+ * @return $this
*/
public function addTypes(array $types = array())
{
@@ -155,8 +159,9 @@ class Search
}
/**
- * @param string|array|\Elastica\Query|\Elastica\Suggest|\Elastica\Query\AbstractQuery|\Elastica\Filter\AbstractFilter $query|
- * @return \Elastica\Search
+ * @param string|array|\Elastica\Query|\Elastica\Suggest|\Elastica\Query\AbstractQuery|\Elastica\Filter\AbstractFilter $query|
+ *
+ * @return $this
*/
public function setQuery($query)
{
@@ -166,9 +171,10 @@ class Search
}
/**
- * @param string $key
- * @param mixed $value
- * @return \Elastica\Search
+ * @param string $key
+ * @param mixed $value
+ *
+ * @return $this
*/
public function setOption($key, $value)
{
@@ -180,8 +186,9 @@ class Search
}
/**
- * @param array $options
- * @return \Elastica\Search
+ * @param array $options
+ *
+ * @return $this
*/
public function setOptions(array $options)
{
@@ -195,7 +202,7 @@ class Search
}
/**
- * @return \Elastica\Search
+ * @return $this
*/
public function clearOptions()
{
@@ -205,9 +212,10 @@ class Search
}
/**
- * @param string $key
- * @param mixed $value
- * @return \Elastica\Search
+ * @param string $key
+ * @param mixed $value
+ *
+ * @return $this
*/
public function addOption($key, $value)
{
@@ -223,7 +231,8 @@ class Search
}
/**
- * @param string $key
+ * @param string $key
+ *
* @return bool
*/
public function hasOption($key)
@@ -232,14 +241,16 @@ class Search
}
/**
- * @param string $key
- * @return mixed
+ * @param string $key
+ *
* @throws \Elastica\Exception\InvalidException
+ *
+ * @return mixed
*/
public function getOption($key)
{
if (!$this->hasOption($key)) {
- throw new InvalidException('Option ' . $key . ' does not exist');
+ throw new InvalidException('Option '.$key.' does not exist');
}
return $this->_options[$key];
@@ -254,9 +265,11 @@ class Search
}
/**
- * @param string $key
- * @return bool
+ * @param string $key
+ *
* @throws \Elastica\Exception\InvalidException
+ *
+ * @return bool
*/
protected function _validateOption($key)
{
@@ -271,14 +284,16 @@ class Search
case self::OPTION_SCROLL:
case self::OPTION_SCROLL_ID:
case self::OPTION_SEARCH_TYPE_SUGGEST:
+ case self::OPTION_SEARCH_IGNORE_UNAVAILABLE:
+ case self::OPTION_QUERY_CACHE:
return true;
}
- throw new InvalidException('Invalid option ' . $key);
+ throw new InvalidException('Invalid option '.$key);
}
/**
- * Return client object
+ * Return client object.
*
* @return \Elastica\Client Client object
*/
@@ -288,7 +303,7 @@ class Search
}
/**
- * Return array of indices
+ * Return array of indices.
*
* @return array List of index names
*/
@@ -307,6 +322,7 @@ class Search
/**
* @param Index|string $index
+ *
* @return bool
*/
public function hasIndex($index)
@@ -319,7 +335,7 @@ class Search
}
/**
- * Return array of types
+ * Return array of types.
*
* @return array List of types
*/
@@ -338,6 +354,7 @@ class Search
/**
* @param \Elastica\Type|string $type
+ *
* @return bool
*/
public function hasType($type)
@@ -362,10 +379,11 @@ class Search
}
/**
- * Creates new search object
+ * Creates new search object.
*
- * @param \Elastica\SearchableInterface $searchObject
- * @return \Elastica\Search
+ * @param \Elastica\SearchableInterface $searchObject
+ *
+ * @return Search
*/
public static function create(SearchableInterface $searchObject)
{
@@ -373,7 +391,7 @@ class Search
}
/**
- * Combines indices and types to the search request path
+ * Combines indices and types to the search request path.
*
* @return string Search path
*/
@@ -397,19 +415,21 @@ class Search
}
if (!empty($types)) {
- $path .= '/' . implode(',', $types);
+ $path .= '/'.implode(',', $types);
}
// Add full path based on indices and types -> could be all
- return $path . '/_search';
+ return $path.'/_search';
}
/**
- * Search in the set indices, types
+ * Search in the set indices, types.
+ *
+ * @param mixed $query
+ * @param int|array $options OPTIONAL Limit or associative array of options (option=>value)
*
- * @param mixed $query
- * @param int|array $options OPTIONAL Limit or associative array of options (option=>value)
* @throws \Elastica\Exception\InvalidException
+ *
* @return \Elastica\ResultSet
*/
public function search($query = '', $options = null)
@@ -436,13 +456,13 @@ class Search
$params
);
- return new ResultSet($response, $query);
+ return ResultSet::create($response, $query);
}
/**
- *
* @param mixed $query
- * @param $fullResult (default = false) By default only the total hit count is returned. If set to true, the full ResultSet including facets is returned.
+ * @param $fullResult (default = false) By default only the total hit count is returned. If set to true, the full ResultSet including aggregations is returned.
+ *
* @return int|ResultSet
*/
public function count($query = '', $fullResult = false)
@@ -458,15 +478,16 @@ class Search
$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();
}
/**
- * @param array|int $options
- * @param string|array|\Elastica\Query $query
- * @return \Elastica\Search
+ * @param array|int $options
+ * @param string|array|\Elastica\Query $query
+ *
+ * @return $this
*/
public function setOptionsAndQuery($options = null, $query = '')
{
@@ -493,7 +514,8 @@ class Search
/**
* @param Suggest $suggest
- * @return Search
+ *
+ * @return $this
*/
public function setSuggest(Suggest $suggest)
{
@@ -501,14 +523,31 @@ class Search
}
/**
- * Returns the ScanAndScroll Iterator
+ * Returns the Scroll Iterator.
+ *
+ * @see Elastica\Scroll
+ *
+ * @param string $expiryTime
+ *
+ * @return Scroll
+ */
+ public function scroll($expiryTime = '1m')
+ {
+ return new Scroll($this, $expiryTime);
+ }
+
+ /**
+ * Returns the ScanAndScroll Iterator.
*
* @see Elastica\ScanAndScroll
+ *
* @param string $expiryTime
- * @param int $sizePerShard
+ * @param int $sizePerShard
+ *
* @return ScanAndScroll
*/
- public function scanAndScroll($expiryTime = '1m', $sizePerShard = 1000) {
+ public function scanAndScroll($expiryTime = '1m', $sizePerShard = 1000)
+ {
return new ScanAndScroll($this, $expiryTime, $sizePerShard);
}
}