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/Filter/GeoDistanceRange.php | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Filter/GeoDistanceRange.php')
-rw-r--r-- | vendor/ruflin/elastica/lib/Elastica/Filter/GeoDistanceRange.php | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Filter/GeoDistanceRange.php b/vendor/ruflin/elastica/lib/Elastica/Filter/GeoDistanceRange.php new file mode 100644 index 00000000..f5cbbeb7 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Filter/GeoDistanceRange.php @@ -0,0 +1,103 @@ +<?php +namespace Elastica\Filter; + +use Elastica\Exception\InvalidException; + +/** + * Geo distance filter. + * + * @author munkie + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-range-filter.html + */ +class GeoDistanceRange extends AbstractGeoDistance +{ + const RANGE_FROM = 'from'; + const RANGE_TO = 'to'; + const RANGE_LT = 'lt'; + const RANGE_LTE = 'lte'; + const RANGE_GT = 'gt'; + const RANGE_GTE = 'gte'; + + const RANGE_INCLUDE_LOWER = 'include_lower'; + const RANGE_INCLUDE_UPPER = 'include_upper'; + + /** + * @var array + */ + protected $_ranges = array(); + + /** + * @param string $key + * @param array|string $location + * @param array $ranges + * + * @internal param string $distance + */ + public function __construct($key, $location, array $ranges = array()) + { + parent::__construct($key, $location); + + if (!empty($ranges)) { + $this->setRanges($ranges); + } + } + + /** + * @param array $ranges + * + * @return $this + */ + public function setRanges(array $ranges) + { + $this->_ranges = array(); + + foreach ($ranges as $key => $value) { + $this->setRange($key, $value); + } + + return $this; + } + + /** + * @param string $key + * @param mixed $value + * + * @throws \Elastica\Exception\InvalidException + * + * @return $this + */ + public function setRange($key, $value) + { + switch ($key) { + case self::RANGE_TO: + case self::RANGE_FROM: + case self::RANGE_GT: + case self::RANGE_GTE: + case self::RANGE_LT: + case self::RANGE_LTE: + break; + case self::RANGE_INCLUDE_LOWER: + case self::RANGE_INCLUDE_UPPER: + $value = (boolean) $value; + break; + default: + throw new InvalidException('Invalid range parameter given: '.$key); + } + $this->_ranges[$key] = $value; + + return $this; + } + + /** + * @return array + */ + public function toArray() + { + foreach ($this->_ranges as $key => $value) { + $this->setParam($key, $value); + } + + return parent::toArray(); + } +} |