diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:15:42 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:44:51 +0100 |
commit | a1789ddde42033f1b05cc4929491214ee6e79383 (patch) | |
tree | 63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/ruflin/elastica/lib/Elastica/Query/Filtered.php | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Query/Filtered.php')
-rw-r--r-- | vendor/ruflin/elastica/lib/Elastica/Query/Filtered.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Filtered.php b/vendor/ruflin/elastica/lib/Elastica/Query/Filtered.php new file mode 100644 index 00000000..ac085037 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Filtered.php @@ -0,0 +1,97 @@ +<?php +namespace Elastica\Query; + +use Elastica\Exception\InvalidException; +use Elastica\Filter\AbstractFilter; + +/** + * Filtered query. Needs a query and a filter. + * + * @author Nicolas Ruflin <spam@ruflin.com> + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html + */ +class Filtered extends AbstractQuery +{ + /** + * Constructs a filtered query. + * + * @param \Elastica\Query\AbstractQuery $query OPTIONAL Query object + * @param \Elastica\Filter\AbstractFilter $filter OPTIONAL Filter object + */ + public function __construct(AbstractQuery $query = null, AbstractFilter $filter = null) + { + $this->setQuery($query); + $this->setFilter($filter); + } + + /** + * Sets a query. + * + * @param \Elastica\Query\AbstractQuery $query Query object + * + * @return $this + */ + public function setQuery(AbstractQuery $query = null) + { + return $this->setParam('query', $query); + } + + /** + * Sets the filter. + * + * @param \Elastica\Filter\AbstractFilter $filter Filter object + * + * @return $this + */ + public function setFilter(AbstractFilter $filter = null) + { + return $this->setParam('filter', $filter); + } + + /** + * Gets the filter. + * + * @return \Elastica\Filter\AbstractFilter + */ + public function getFilter() + { + return $this->getParam('filter'); + } + + /** + * Gets the query. + * + * @return \Elastica\Query\AbstractQuery + */ + public function getQuery() + { + return $this->getParam('query'); + } + + /** + * Converts query to array. + * + * @return array Query array + * + * @see \Elastica\Query\AbstractQuery::toArray() + */ + public function toArray() + { + $filtered = array(); + + if ($this->hasParam('query') && $this->getParam('query') instanceof AbstractQuery) { + $filtered['query'] = $this->getParam('query')->toArray(); + } + + if ($this->hasParam('filter') && $this->getParam('filter') instanceof AbstractFilter) { + $filtered['filter'] = $this->getParam('filter')->toArray(); + } + + if (empty($filtered)) { + throw new InvalidException('A query and/or filter is required'); + } + + return array('filtered' => $filtered); + } +} |