diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
commit | 6dc1997577fab2c366781fd7048144935afa0012 (patch) | |
tree | 8918d28c7ab4342f0738985e37af1dfc42d0e93a /vendor/ruflin/elastica/lib/Elastica/Aggregation | |
parent | 150f94f051128f367bc89f6b7e5f57eb2a69fc62 (diff) | |
parent | fa89acd685cb09cdbe1c64cbb721ec64975bbbc1 (diff) |
Merge commit 'fa89acd'
# Conflicts:
# .gitignore
# extensions/ArchInterWiki.sql
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Aggregation')
29 files changed, 1463 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php new file mode 100644 index 00000000..4cbb6b74 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php @@ -0,0 +1,97 @@ +<?php +namespace Elastica\Aggregation; + +use Elastica\Exception\InvalidException; +use Elastica\Param; + +abstract class AbstractAggregation extends Param +{ + /** + * @var string The name of this aggregation + */ + protected $_name; + + /** + * @var array Subaggregations belonging to this aggregation + */ + protected $_aggs = array(); + + /** + * @param string $name the name of this aggregation + */ + public function __construct($name) + { + $this->setName($name); + } + + /** + * Set the name of this aggregation. + * + * @param string $name + * + * @return $this + */ + public function setName($name) + { + $this->_name = $name; + + return $this; + } + + /** + * Retrieve the name of this aggregation. + * + * @return string + */ + public function getName() + { + return $this->_name; + } + + /** + * Retrieve all subaggregations belonging to this aggregation. + * + * @return array + */ + public function getAggs() + { + return $this->_aggs; + } + + /** + * Add a sub-aggregation. + * + * @param AbstractAggregation $aggregation + * + * @throws \Elastica\Exception\InvalidException + * + * @return $this + */ + public function addAggregation(AbstractAggregation $aggregation) + { + if ($aggregation instanceof GlobalAggregation) { + throw new InvalidException('Global aggregators can only be placed as top level aggregators'); + } + + $this->_aggs[$aggregation->getName()] = $aggregation->toArray(); + + return $this; + } + + /** + * @return array + */ + public function toArray() + { + $array = parent::toArray(); + if (array_key_exists('global_aggregation', $array)) { + // compensate for class name GlobalAggregation + $array = array('global' => new \stdClass()); + } + if (sizeof($this->_aggs)) { + $array['aggs'] = $this->_aggs; + } + + return $array; + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractSimpleAggregation.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractSimpleAggregation.php new file mode 100644 index 00000000..02a0fddb --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractSimpleAggregation.php @@ -0,0 +1,37 @@ +<?php +namespace Elastica\Aggregation; + +use Elastica\Script; + +abstract class AbstractSimpleAggregation extends AbstractAggregation +{ + /** + * Set the field for this aggregation. + * + * @param string $field the name of the document field on which to perform this aggregation + * + * @return $this + */ + public function setField($field) + { + return $this->setParam('field', $field); + } + + /** + * Set a script for this aggregation. + * + * @param string|Script $script + * + * @return $this + */ + public function setScript($script) + { + if ($script instanceof Script) { + $params = array_merge($this->getParams(), $script->toArray()); + + return $this->setParams($params); + } + + return $this->setParam('script', $script); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractTermsAggregation.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractTermsAggregation.php new file mode 100644 index 00000000..57b56964 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractTermsAggregation.php @@ -0,0 +1,97 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class AbstractTermsAggergation. + */ +abstract class AbstractTermsAggregation extends AbstractSimpleAggregation +{ + /** + * Set the minimum number of documents in which a term must appear in order to be returned in a bucket. + * + * @param int $count + * + * @return $this + */ + public function setMinimumDocumentCount($count) + { + return $this->setParam('min_doc_count', $count); + } + + /** + * Filter documents to include based on a regular expression. + * + * @param string $pattern a regular expression + * @param string $flags Java Pattern flags + * + * @return $this + */ + public function setInclude($pattern, $flags = null) + { + if (is_null($flags)) { + return $this->setParam('include', $pattern); + } + + return $this->setParam('include', array( + 'pattern' => $pattern, + 'flags' => $flags, + )); + } + + /** + * Filter documents to exclude based on a regular expression. + * + * @param string $pattern a regular expression + * @param string $flags Java Pattern flags + * + * @return $this + */ + public function setExclude($pattern, $flags = null) + { + if (is_null($flags)) { + return $this->setParam('exclude', $pattern); + } + + return $this->setParam('exclude', array( + 'pattern' => $pattern, + 'flags' => $flags, + )); + } + + /** + * Sets the amount of terms to be returned. + * + * @param int $size The amount of terms to be returned. + * + * @return $this + */ + public function setSize($size) + { + return $this->setParam('size', $size); + } + + /** + * Sets how many terms the coordinating node will request from each shard. + * + * @param int $shard_size The amount of terms to be returned. + * + * @return $this + */ + public function setShardSize($shard_size) + { + return $this->setParam('shard_size', $shard_size); + } + + /** + * Instruct Elasticsearch to use direct field data or ordinals of the field values to execute this aggregation. + * The execution hint will be ignored if it is not applicable. + * + * @param string $hint map or ordinals + * + * @return $this + */ + public function setExecutionHint($hint) + { + return $this->setParam('execution_hint', $hint); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Avg.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Avg.php new file mode 100644 index 00000000..abc2f7a1 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Avg.php @@ -0,0 +1,11 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class Avg. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html + */ +class Avg extends AbstractSimpleAggregation +{ +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Cardinality.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Cardinality.php new file mode 100644 index 00000000..72b2e3aa --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Cardinality.php @@ -0,0 +1,38 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class Cardinality. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html + */ +class Cardinality extends AbstractSimpleAggregation +{ + /** + * @param int $precisionThreshold + * + * @return $this + */ + public function setPrecisionThreshold($precisionThreshold) + { + if (!is_int($precisionThreshold)) { + throw new \InvalidArgumentException('precision_threshold only supports integer values'); + } + + return $this->setParam('precision_threshold', $precisionThreshold); + } + + /** + * @param bool $rehash + * + * @return $this + */ + public function setRehash($rehash) + { + if (!is_bool($rehash)) { + throw new \InvalidArgumentException('rehash only supports boolean values'); + } + + return $this->setParam('rehash', $rehash); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/DateHistogram.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/DateHistogram.php new file mode 100644 index 00000000..8636f34c --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/DateHistogram.php @@ -0,0 +1,130 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class DateHistogram. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html + */ +class DateHistogram extends Histogram +{ + /** + * Set pre-rounding based on interval. + * + * @deprecated Option "pre_zone" is deprecated as of ES 1.5. Use "time_zone" instead + * + * @param string $preZone + * + * @return $this + */ + public function setPreZone($preZone) + { + return $this->setParam('pre_zone', $preZone); + } + + /** + * Set post-rounding based on interval. + * + * @deprecated Option "post_zone" is deprecated as of ES 1.5. Use "time_zone" instead + * + * @param string $postZone + * + * @return $this + */ + public function setPostZone($postZone) + { + return $this->setParam('post_zone', $postZone); + } + + /** + * Set time_zone option. + * + * @param string + * + * @return $this + */ + public function setTimezone($timezone) + { + return $this->setParam('time_zone', $timezone); + } + + /** + * Set pre-zone adjustment for larger time intervals (day and above). + * + * @deprecated Option "pre_zone_adjust_large_interval" is deprecated as of ES 1.5 + * + * @param string $adjust + * + * @return $this + */ + public function setPreZoneAdjustLargeInterval($adjust) + { + return $this->setParam('pre_zone_adjust_large_interval', $adjust); + } + + /** + * Adjust for granularity of date data. + * + * @param int $factor set to 1000 if date is stored in seconds rather than milliseconds + * + * @return $this + */ + public function setFactor($factor) + { + return $this->setParam('factor', $factor); + } + + /** + * Set the offset for pre-rounding. + * + * @deprecated Option "pre_offset" is deprecated as of ES 1.5. Use "offset" instead + * + * @param string $offset "1d", for example + * + * @return $this + */ + public function setPreOffset($offset) + { + return $this->setParam('pre_offset', $offset); + } + + /** + * Set the offset for post-rounding. + * + * @deprecated Option "post_offset" is deprecated as of ES 1.5. Use "offset" instead + * + * @param string $offset "1d", for example + * + * @return $this + */ + public function setPostOffset($offset) + { + return $this->setParam('post_offset', $offset); + } + + /** + * Set offset option. + * + * @param string + * + * @return $this + */ + public function setOffset($offset) + { + return $this->setParam('offset', $offset); + } + + /** + * Set the format for returned bucket key_as_string values. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern + * + * @param string $format see link for formatting options + * + * @return $this + */ + public function setFormat($format) + { + return $this->setParam('format', $format); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/DateRange.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/DateRange.php new file mode 100644 index 00000000..deb5881d --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/DateRange.php @@ -0,0 +1,22 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class DateRange. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html + */ +class DateRange extends Range +{ + /** + * Set the formatting for the returned date values. + * + * @param string $format see documentation for formatting options + * + * @return $this + */ + public function setFormat($format) + { + return $this->setParam('format', $format); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/ExtendedStats.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/ExtendedStats.php new file mode 100644 index 00000000..2b108bd1 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/ExtendedStats.php @@ -0,0 +1,11 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class ExtendedStats. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-extendedstats-aggregation.html + */ +class ExtendedStats extends AbstractSimpleAggregation +{ +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Filter.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Filter.php new file mode 100644 index 00000000..fc83419e --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Filter.php @@ -0,0 +1,53 @@ +<?php +namespace Elastica\Aggregation; + +use Elastica\Filter\AbstractFilter; + +/** + * Class Filter. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html + */ +class Filter extends AbstractAggregation +{ + /** + * @param string $name + * @param AbstractFilter $filter + */ + public function __construct($name, AbstractFilter $filter = null) + { + parent::__construct($name); + + if ($filter !== null) { + $this->setFilter($filter); + } + } + + /** + * Set the filter for this aggregation. + * + * @param AbstractFilter $filter + * + * @return $this + */ + public function setFilter(AbstractFilter $filter) + { + return $this->setParam('filter', $filter->toArray()); + } + + /** + * @return array + */ + public function toArray() + { + $array = array( + 'filter' => $this->getParam('filter'), + ); + + if ($this->_aggs) { + $array['aggs'] = $this->_aggs; + } + + return $array; + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Filters.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Filters.php new file mode 100644 index 00000000..e0fbf060 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Filters.php @@ -0,0 +1,59 @@ +<?php +namespace Elastica\Aggregation; + +use Elastica\Filter\AbstractFilter; + +/** + * Class Filters. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html + */ +class Filters extends AbstractAggregation +{ + /** + * Add a filter. + * + * If a name is given, it will be added as a key, otherwise considered as an anonymous filter + * + * @param AbstractFilter $filter + * @param string $name + * + * @return $this + */ + public function addFilter(AbstractFilter $filter, $name = '') + { + if (empty($name)) { + $filterArray[] = $filter->toArray(); + } else { + $filterArray[$name] = $filter->toArray(); + } + + return $this->addParam('filters', $filterArray); + } + + /** + * @return array + */ + public function toArray() + { + $array = array(); + $filters = $this->getParam('filters'); + + foreach ($filters as $filter) { + // Detect between anonymous filters and named ones + $key = key($filter); + + if (is_string($key)) { + $array['filters']['filters'][$key] = current($filter); + } else { + $array['filters']['filters'][] = current($filter); + } + } + + if ($this->_aggs) { + $array['aggs'] = $this->_aggs; + } + + return $array; + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/GeoDistance.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/GeoDistance.php new file mode 100644 index 00000000..c50018a0 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/GeoDistance.php @@ -0,0 +1,104 @@ +<?php +namespace Elastica\Aggregation; + +use Elastica\Exception\InvalidException; + +/** + * Class GeoDistance. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html + */ +class GeoDistance extends AbstractAggregation +{ + const DISTANCE_TYPE_SLOPPY_ARC = 'sloppy_arc'; + const DISTANCE_TYPE_ARC = 'arc'; + const DISTANCE_TYPE_PLANE = 'plane'; + + /** + * @param string $name the name if this aggregation + * @param string $field the field on which to perform this aggregation + * @param string|array $origin the point from which distances will be calculated + */ + public function __construct($name, $field, $origin) + { + parent::__construct($name); + $this->setField($field)->setOrigin($origin); + } + + /** + * Set the field for this aggregation. + * + * @param string $field the name of the document field on which to perform this aggregation + * + * @return $this + */ + public function setField($field) + { + return $this->setParam('field', $field); + } + + /** + * Set the origin point from which distances will be calculated. + * + * @param string|array $origin valid formats are array("lat" => 52.3760, "lon" => 4.894), "52.3760, 4.894", and array(4.894, 52.3760) + * + * @return $this + */ + public function setOrigin($origin) + { + return $this->setParam('origin', $origin); + } + + /** + * Add a distance range to this aggregation. + * + * @param int $fromValue a distance + * @param int $toValue a distance + * + * @throws \Elastica\Exception\InvalidException + * + * @return $this + */ + public function addRange($fromValue = null, $toValue = null) + { + if (is_null($fromValue) && is_null($toValue)) { + throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.'); + } + + $range = array(); + + if (!is_null($fromValue)) { + $range['from'] = $fromValue; + } + + if (!is_null($toValue)) { + $range['to'] = $toValue; + } + + return $this->addParam('ranges', $range); + } + + /** + * Set the unit of distance measure for this aggregation. + * + * @param string $unit defaults to km + * + * @return $this + */ + public function setUnit($unit) + { + return $this->setParam('unit', $unit); + } + + /** + * Set the method by which distances will be calculated. + * + * @param string $distanceType see DISTANCE_TYPE_* constants for options. Defaults to sloppy_arc. + * + * @return $this + */ + public function setDistanceType($distanceType) + { + return $this->setParam('distance_type', $distanceType); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/GeohashGrid.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/GeohashGrid.php new file mode 100644 index 00000000..e7a40471 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/GeohashGrid.php @@ -0,0 +1,68 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class GeohashGrid. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html + */ +class GeohashGrid extends AbstractAggregation +{ + /** + * @param string $name the name of this aggregation + * @param string $field the field on which to perform this aggregation + */ + public function __construct($name, $field) + { + parent::__construct($name); + $this->setField($field); + } + + /** + * Set the field for this aggregation. + * + * @param string $field the name of the document field on which to perform this aggregation + * + * @return $this + */ + public function setField($field) + { + return $this->setParam('field', $field); + } + + /** + * Set the precision for this aggregation. + * + * @param int $precision an integer between 1 and 12, inclusive. Defaults to 5. + * + * @return $this + */ + public function setPrecision($precision) + { + return $this->setParam('precision', $precision); + } + + /** + * Set the maximum number of buckets to return. + * + * @param int $size defaults to 10,000 + * + * @return $this + */ + public function setSize($size) + { + return $this->setParam('size', $size); + } + + /** + * Set the number of results returned from each shard. + * + * @param int $shardSize + * + * @return $this + */ + public function setShardSize($shardSize) + { + return $this->setParam('shard_size', $shardSize); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/GlobalAggregation.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/GlobalAggregation.php new file mode 100644 index 00000000..523844d2 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/GlobalAggregation.php @@ -0,0 +1,11 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class GlobalAggregation. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html + */ +class GlobalAggregation extends AbstractAggregation +{ +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Histogram.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Histogram.php new file mode 100644 index 00000000..79a8e517 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Histogram.php @@ -0,0 +1,59 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class Histogram. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html + */ +class Histogram extends AbstractSimpleAggregation +{ + /** + * @param string $name the name of this aggregation + * @param string $field the name of the field on which to perform the aggregation + * @param int $interval the interval by which documents will be bucketed + */ + public function __construct($name, $field, $interval) + { + parent::__construct($name); + $this->setField($field); + $this->setInterval($interval); + } + + /** + * Set the interval by which documents will be bucketed. + * + * @param int $interval + * + * @return $this + */ + public function setInterval($interval) + { + return $this->setParam('interval', $interval); + } + + /** + * Set the bucket sort order. + * + * @param string $order "_count", "_term", or the name of a sub-aggregation or sub-aggregation response field + * @param string $direction "asc" or "desc" + * + * @return $this + */ + public function setOrder($order, $direction) + { + return $this->setParam('order', array($order => $direction)); + } + + /** + * Set the minimum number of documents which must fall into a bucket in order for the bucket to be returned. + * + * @param int $count set to 0 to include empty buckets + * + * @return $this + */ + public function setMinimumDocumentCount($count) + { + return $this->setParam('min_doc_count', $count); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/IpRange.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/IpRange.php new file mode 100644 index 00000000..7a4ef7c8 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/IpRange.php @@ -0,0 +1,72 @@ +<?php +namespace Elastica\Aggregation; + +use Elastica\Exception\InvalidException; + +/** + * Class IpRange. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-iprange-aggregation.html + */ +class IpRange extends AbstractAggregation +{ + /** + * @param string $name the name of this aggregation + * @param string $field the field on which to perform this aggregation + */ + public function __construct($name, $field) + { + parent::__construct($name); + $this->setField($field); + } + + /** + * Set the field for this aggregation. + * + * @param string $field the name of the document field on which to perform this aggregation + * + * @return $this + */ + public function setField($field) + { + return $this->setParam('field', $field); + } + + /** + * Add an ip range to this aggregation. + * + * @param string $fromValue a valid ipv4 address. Low end of this range, exclusive (greater than) + * @param string $toValue a valid ipv4 address. High end of this range, exclusive (less than) + * + * @throws \Elastica\Exception\InvalidException + * + * @return $this + */ + public function addRange($fromValue = null, $toValue = null) + { + if (is_null($fromValue) && is_null($toValue)) { + throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.'); + } + $range = array(); + if (!is_null($fromValue)) { + $range['from'] = $fromValue; + } + if (!is_null($toValue)) { + $range['to'] = $toValue; + } + + return $this->addParam('ranges', $range); + } + + /** + * Add an ip range in the form of a CIDR mask. + * + * @param string $mask a valid CIDR mask + * + * @return $this + */ + public function addMaskRange($mask) + { + return $this->addParam('ranges', array('mask' => $mask)); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Max.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Max.php new file mode 100644 index 00000000..fc0294ca --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Max.php @@ -0,0 +1,11 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class Max. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html + */ +class Max extends AbstractSimpleAggregation +{ +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Min.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Min.php new file mode 100644 index 00000000..d5c5c31b --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Min.php @@ -0,0 +1,11 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class Min. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html + */ +class Min extends AbstractSimpleAggregation +{ +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Missing.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Missing.php new file mode 100644 index 00000000..11a6bdf9 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Missing.php @@ -0,0 +1,32 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class Missing. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html + */ +class Missing extends AbstractAggregation +{ + /** + * @param string $name the name of this aggregation + * @param string $field the field on which to perform this aggregation + */ + public function __construct($name, $field) + { + parent::__construct($name); + $this->setField($field); + } + + /** + * Set the field for this aggregation. + * + * @param string $field the name of the document field on which to perform this aggregation + * + * @return $this + */ + public function setField($field) + { + return $this->setParam('field', $field); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Nested.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Nested.php new file mode 100644 index 00000000..76407bc8 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Nested.php @@ -0,0 +1,32 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class Nested. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html + */ +class Nested extends AbstractAggregation +{ + /** + * @param string $name the name of this aggregation + * @param string $path the nested path for this aggregation + */ + public function __construct($name, $path) + { + parent::__construct($name); + $this->setPath($path); + } + + /** + * Set the nested path for this aggregation. + * + * @param string $path + * + * @return $this + */ + public function setPath($path) + { + return $this->setParam('path', $path); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Percentiles.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Percentiles.php new file mode 100644 index 00000000..22079634 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Percentiles.php @@ -0,0 +1,59 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class Percentiles. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html + */ +class Percentiles extends AbstractSimpleAggregation +{ + /** + * @param string $name the name of this aggregation + * @param string $field the field on which to perform this aggregation + */ + public function __construct($name, $field = null) + { + parent::__construct($name); + + if (!is_null($field)) { + $this->setField($field); + } + } + + /** + * Set compression parameter. + * + * @param float $value + * + * @return $this + */ + public function setCompression($value) + { + return $this->setParam('compression', (float) $value); + } + + /** + * Set which percents must be returned. + * + * @param float[] $percents + * + * @return $this + */ + public function setPercents(array $percents) + { + return $this->setParam('percents', $percents); + } + + /** + * Add yet another percent to result. + * + * @param float $percent + * + * @return $this + */ + public function addPercent($percent) + { + return $this->addParam('percents', (float) $percent); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Range.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Range.php new file mode 100644 index 00000000..becafb28 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Range.php @@ -0,0 +1,58 @@ +<?php +namespace Elastica\Aggregation; + +use Elastica\Exception\InvalidException; + +/** + * Class Range. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html + */ +class Range extends AbstractSimpleAggregation +{ + /** + * Add a range to this aggregation. + * + * @param int|float $fromValue low end of this range, exclusive (greater than or equal to) + * @param int|float $toValue high end of this range, exclusive (less than) + * @param string $key customized key value + * + * @throws \Elastica\Exception\InvalidException + * + * @return $this + */ + public function addRange($fromValue = null, $toValue = null, $key = null) + { + if (is_null($fromValue) && is_null($toValue)) { + throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.'); + } + + $range = array(); + + if (!is_null($fromValue)) { + $range['from'] = $fromValue; + } + + if (!is_null($toValue)) { + $range['to'] = $toValue; + } + + if (!is_null($key)) { + $range['key'] = $key; + } + + return $this->addParam('ranges', $range); + } + + /** + * If set to true, a unique string key will be associated with each bucket, and ranges will be returned as an associative array. + * + * @param bool $keyed + * + * @return $this + */ + public function setKeyedResponse($keyed = true) + { + return $this->setParam('keyed', (bool) $keyed); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/ReverseNested.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/ReverseNested.php new file mode 100644 index 00000000..5216ae85 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/ReverseNested.php @@ -0,0 +1,49 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Reversed Nested Aggregation. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html + */ +class ReverseNested extends AbstractAggregation +{ + /** + * @param string $name The name of this aggregation + * @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document. + */ + public function __construct($name, $path = null) + { + parent::__construct($name); + + if ($path !== null) { + $this->setPath($path); + } + } + + /** + * Set the nested path for this aggregation. + * + * @param string $path + * + * @return $this + */ + public function setPath($path) + { + return $this->setParam('path', $path); + } + + /** + * {@inheritDoc} + */ + public function toArray() + { + $array = parent::toArray(); + + // ensure we have an object for the reverse_nested key. + // if we don't have a path, then this would otherwise get encoded as an empty array, which is invalid. + $array['reverse_nested'] = (object) $array['reverse_nested']; + + return $array; + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/ScriptedMetric.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/ScriptedMetric.php new file mode 100644 index 00000000..3e51f056 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/ScriptedMetric.php @@ -0,0 +1,82 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class ScriptedMetric. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html + */ +class ScriptedMetric extends AbstractAggregation +{ + /** + * @param string $name the name if this aggregation + * @param string|null $initScript Executed prior to any collection of documents + * @param string|null $mapScript Executed once per document collected + * @param string|null $combineScript Executed once on each shard after document collection is complete + * @param string|null $reduceScript Executed once on the coordinating node after all shards have returned their results + */ + public function __construct($name, $initScript = null, $mapScript = null, $combineScript = null, $reduceScript = null) + { + parent::__construct($name); + if ($initScript) { + $this->setInitScript($initScript); + } + if ($mapScript) { + $this->setMapScript($mapScript); + } + if ($combineScript) { + $this->setCombineScript($combineScript); + } + if ($reduceScript) { + $this->setReduceScript($reduceScript); + } + } + + /** + * Set the field for this aggregation. + * + * @param string $script the name of the document field on which to perform this aggregation + * + * @return $this + */ + public function setCombineScript($script) + { + return $this->setParam('combine_script', $script); + } + + /** + * Set the field for this aggregation. + * + * @param string $script the name of the document field on which to perform this aggregation + * + * @return $this + */ + public function setInitScript($script) + { + return $this->setParam('init_script', $script); + } + + /** + * Set the field for this aggregation. + * + * @param string $script the name of the document field on which to perform this aggregation + * + * @return $this + */ + public function setMapScript($script) + { + return $this->setParam('map_script', $script); + } + + /** + * Set the field for this aggregation. + * + * @param string $script the name of the document field on which to perform this aggregation + * + * @return $this + */ + public function setReduceScript($script) + { + return $this->setParam('reduce_script', $script); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/SignificantTerms.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/SignificantTerms.php new file mode 100644 index 00000000..fa394791 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/SignificantTerms.php @@ -0,0 +1,27 @@ +<?php +namespace Elastica\Aggregation; + +use Elastica\Filter\AbstractFilter; + +/** + * Class SignificantTerms. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html + */ +class SignificantTerms extends AbstractTermsAggregation +{ + /** + * The default source of statistical information for background term frequencies is the entire index and this scope can + * be narrowed through the use of a background_filter to focus in on significant terms within a narrower context. + * + * @param AbstractFilter $filter + * + * @return $this + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_custom_background_context + */ + public function setBackgroundFilter(AbstractFilter $filter) + { + return $this->setParam('background_filter', $filter->toArray()); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Stats.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Stats.php new file mode 100644 index 00000000..f512628c --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Stats.php @@ -0,0 +1,11 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class Stats. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html + */ +class Stats extends AbstractSimpleAggregation +{ +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Sum.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Sum.php new file mode 100644 index 00000000..5172a684 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Sum.php @@ -0,0 +1,11 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class Sum. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html + */ +class Sum extends AbstractSimpleAggregation +{ +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Terms.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Terms.php new file mode 100644 index 00000000..8d0d6bef --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Terms.php @@ -0,0 +1,23 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class Terms. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html + */ +class Terms extends AbstractTermsAggregation +{ + /** + * Set the bucket sort order. + * + * @param string $order "_count", "_term", or the name of a sub-aggregation or sub-aggregation response field + * @param string $direction "asc" or "desc" + * + * @return $this + */ + public function setOrder($order, $direction) + { + return $this->setParam('order', array($order => $direction)); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/TopHits.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/TopHits.php new file mode 100644 index 00000000..91a48a48 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/TopHits.php @@ -0,0 +1,156 @@ +<?php +namespace Elastica\Aggregation; + +use Elastica\Script; +use Elastica\ScriptFields; + +/** + * Class TopHits. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html + */ +class TopHits extends AbstractAggregation +{ + /** + * @return array + */ + public function toArray() + { + $array = parent::toArray(); + + // if there are no params, it's ok, but ES will throw exception if json + // will be like {"top_hits":[]} instead of {"top_hits":{}} + if (empty($array['top_hits'])) { + $array['top_hits'] = new \stdClass(); + } + + return $array; + } + + /** + * The maximum number of top matching hits to return per bucket. By default the top three matching hits are returned. + * + * @param int $size + * + * @return $this + */ + public function setSize($size) + { + return $this->setParam('size', (int) $size); + } + + /** + * The offset from the first result you want to fetch. + * + * @param int $from + * + * @return $this + */ + public function setFrom($from) + { + return $this->setParam('from', (int) $from); + } + + /** + * How the top matching hits should be sorted. By default the hits are sorted by the score of the main query. + * + * @param array $sortArgs + * + * @return $this + */ + public function setSort(array $sortArgs) + { + return $this->setParam('sort', $sortArgs); + } + + /** + * Allows to control how the _source field is returned with every hit. + * + * @param array $fields + * + * @return $this + */ + public function setSource(array $fields) + { + return $this->setParam('_source', $fields); + } + + /** + * Returns a version for each search hit. + * + * @param bool $version + * + * @return $this + */ + public function setVersion($version) + { + return $this->setParam('version', (bool) $version); + } + + /** + * Enables explanation for each hit on how its score was computed. + * + * @param bool $explain + * + * @return $this + */ + public function setExplain($explain) + { + return $this->setParam('explain', (bool) $explain); + } + + /** + * Set script fields. + * + * @param array|\Elastica\ScriptFields $scriptFields + * + * @return $this + */ + public function setScriptFields($scriptFields) + { + if (is_array($scriptFields)) { + $scriptFields = new ScriptFields($scriptFields); + } + + return $this->setParam('script_fields', $scriptFields->toArray()); + } + + /** + * Adds a Script to the aggregation. + * + * @param string $name + * @param \Elastica\Script $script + * + * @return $this + */ + public function addScriptField($name, Script $script) + { + $this->_params['script_fields'][$name] = $script->toArray(); + + return $this; + } + + /** + * Sets highlight arguments for the results. + * + * @param array $highlightArgs + * + * @return $this + */ + public function setHighlight(array $highlightArgs) + { + return $this->setParam('highlight', $highlightArgs); + } + + /** + * Allows to return the field data representation of a field for each hit. + * + * @param array $fields + * + * @return $this + */ + public function setFieldDataFields(array $fields) + { + return $this->setParam('fielddata_fields', $fields); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/ValueCount.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/ValueCount.php new file mode 100644 index 00000000..8706a1be --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/ValueCount.php @@ -0,0 +1,32 @@ +<?php +namespace Elastica\Aggregation; + +/** + * Class ValueCount. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html + */ +class ValueCount extends AbstractAggregation +{ + /** + * @param string $name the name of this aggregation + * @param string $field the field on which to perform this aggregation + */ + public function __construct($name, $field) + { + parent::__construct($name); + $this->setField($field); + } + + /** + * Set the field for this aggregation. + * + * @param string $field the name of the document field on which to perform this aggregation + * + * @return $this + */ + public function setField($field) + { + return $this->setParam('field', $field); + } +} |