summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Facet
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Facet')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/AbstractFacet.php141
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/DateHistogram.php44
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/Filter.php27
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/GeoCluster.php54
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/GeoDistance.php66
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/Histogram.php90
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/Query.php27
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/Range.php138
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/Statistical.php61
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/Terms.php129
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/TermsStats.php103
11 files changed, 880 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Facet/AbstractFacet.php b/vendor/ruflin/elastica/lib/Elastica/Facet/AbstractFacet.php
new file mode 100644
index 00000000..25cee812
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/AbstractFacet.php
@@ -0,0 +1,141 @@
+<?php
+
+namespace Elastica\Facet;
+
+use Elastica\Param;
+use Elastica\Filter\AbstractFilter;
+use Elastica\Exception\InvalidException;
+
+/**
+ * Abstract facet object. Should be extended by all facet types
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Nicolas Ruflin <spam@ruflin.com>
+ * @author Jasper van Wanrooy <jasper@vanwanrooy.net>
+ */
+abstract class AbstractFacet extends Param
+{
+ /**
+ * Holds the name of the facet.
+ * @var string
+ */
+ protected $_name = '';
+
+ /**
+ * Holds all facet parameters.
+ * @var array
+ */
+ protected $_facet = array();
+
+ /**
+ * Constructs a Facet object.
+ *
+ * @param string $name The name of the facet.
+ */
+ public function __construct($name)
+ {
+ $this->setName($name);
+ }
+
+ /**
+ * Sets the name of the facet. It is automatically set by
+ * the constructor.
+ *
+ * @param string $name The name of the facet.
+ * @throws \Elastica\Exception\InvalidException
+ * @return \Elastica\Facet\AbstractFacet
+ */
+ public function setName($name)
+ {
+ if (empty($name)) {
+ throw new InvalidException('Facet name has to be set');
+ }
+ $this->_name = $name;
+
+ return $this;
+ }
+
+ /**
+ * Gets the name of the facet.
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->_name;
+ }
+
+ /**
+ * Sets a filter for this facet.
+ *
+ * @param \Elastica\Filter\AbstractFilter $filter A filter to apply on the facet.
+ * @return \Elastica\Facet\AbstractFacet
+ */
+ public function setFilter(AbstractFilter $filter)
+ {
+ return $this->_setFacetParam('facet_filter', $filter->toArray());
+ }
+
+ /**
+ * Sets the flag to either run the facet globally or bound to the
+ * current search query. When not set, it defaults to the
+ * Elasticsearch default value.
+ *
+ * @param bool $global Flag to either run the facet globally.
+ * @return \Elastica\Facet\AbstractFacet
+ */
+ public function setGlobal($global = true)
+ {
+ return $this->_setFacetParam('global', (bool) $global);
+ }
+
+ /**
+ * Sets the path to the nested document
+ *
+ * @param string $nestedPath Nested path
+ * @return \Elastica\Facet\AbstractFacet
+ */
+ public function setNested($nestedPath)
+ {
+ return $this->_setFacetParam('nested', $nestedPath);
+ }
+
+ /**
+ * Sets the scope
+ *
+ * @param string $scope Scope
+ * @return \Elastica\Facet\AbstractFacet
+ */
+ public function setScope($scope)
+ {
+ return $this->_setFacetParam('scope', $scope);
+ }
+
+ /**
+ * Basic definition of all specs of the facet. Each implementation
+ * should override this function in order to set it's specific
+ * settings.
+ *
+ * @return array
+ */
+ public function toArray()
+ {
+ return $this->_facet;
+ }
+
+ /**
+ * Sets a param for the facet. Each facet implementation needs to take
+ * care of handling their own params.
+ *
+ * @param string $key The key of the param to set.
+ * @param mixed $value The value of the param.
+ * @return \Elastica\Facet\AbstractFacet
+ */
+ protected function _setFacetParam($key, $value)
+ {
+ $this->_facet[$key] = $value;
+
+ return $this;
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Facet/DateHistogram.php b/vendor/ruflin/elastica/lib/Elastica/Facet/DateHistogram.php
new file mode 100644
index 00000000..803f54a3
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/DateHistogram.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Elastica\Facet;
+
+/**
+ * Implements the Date Histogram facet.
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Raul Martinez Jr <juneym@gmail.com>
+ * @link http://www.elasticsearch.org/guide/reference/api/search/facets/date-histogram-facet.html
+ * @link https://github.com/elasticsearch/elasticsearch/issues/591
+ */
+class DateHistogram extends Histogram
+{
+ /**
+ * Set the time_zone parameter
+ *
+ * @param string $tzOffset
+ * @return \Elastica\Facet\DateHistogram
+ */
+ public function setTimezone($tzOffset)
+ {
+ return $this->setParam('time_zone', $tzOffset);
+ }
+
+ /**
+ * Creates the full facet definition, which includes the basic
+ * facet definition of the parent.
+ *
+ * @see \Elastica\Facet\AbstractFacet::toArray()
+ * @throws \Elastica\Exception\InvalidException When the right fields haven't been set.
+ * @return array
+ */
+ public function toArray()
+ {
+ /**
+ * Set the range in the abstract as param.
+ */
+ $this->_setFacetParam('date_histogram', $this->_params);
+
+ return $this->_facet;
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Facet/Filter.php b/vendor/ruflin/elastica/lib/Elastica/Facet/Filter.php
new file mode 100644
index 00000000..ed6f28b7
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/Filter.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Elastica\Facet;
+
+use Elastica\Filter\AbstractFilter;
+
+/**
+ * Filter facet
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Nicolas Ruflin <spam@ruflin.com>
+ * @link http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html
+ */
+class Filter extends AbstractFacet
+{
+ /**
+ * Set the filter for the facet.
+ *
+ * @param \Elastica\Filter\AbstractFilter $filter
+ * @return \Elastica\Facet\Filter
+ */
+ public function setFilter(AbstractFilter $filter)
+ {
+ return $this->_setFacetParam('filter', $filter->toArray());
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Facet/GeoCluster.php b/vendor/ruflin/elastica/lib/Elastica/Facet/GeoCluster.php
new file mode 100644
index 00000000..a6f5e9ed
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/GeoCluster.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Elastica\Facet;
+
+/**
+ * Implements the Geo Cluster facet.
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Konstantin Nikiforov <konstantin.nikiforov@gmail.com>
+ * @link https://github.com/zenobase/geocluster-facet
+ */
+class GeoCluster extends AbstractFacet {
+
+ /**
+ * @param string $fieldName
+ * @return $this
+ */
+ public function setField($fieldName) {
+ $this->setParam('field', $fieldName);
+ return $this;
+ }
+
+ /**
+ * @param double $factor
+ * @return $this
+ */
+ public function setFactor($factor){
+ $this->setParam('factor', $factor);
+ return $this;
+ }
+
+ /**
+ * @param boolean $showIds
+ * @return $this
+ */
+ public function setShowIds($showIds) {
+ $this->setParam('showIds', $showIds);
+ return $this;
+ }
+
+ /**
+ * Creates the full facet definition, which includes the basic
+ * facet definition of the parent.
+ *
+ * @see \Elastica\Facet\AbstractFacet::toArray()
+ * @throws \Elastica\Exception\InvalidException When the right fields haven't been set.
+ * @return array
+ */
+ public function toArray(){
+ $this->_setFacetParam ('geo_cluster', $this->_params);
+ return parent::toArray();
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Facet/GeoDistance.php b/vendor/ruflin/elastica/lib/Elastica/Facet/GeoDistance.php
new file mode 100644
index 00000000..35537986
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/GeoDistance.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Elastica\Facet;
+
+/**
+ * Implements the Geo Distance facet.
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Gerard A. Matthew <gerard.matthew@gmail.com>
+ * @link http://www.elasticsearch.org/guide/reference/api/search/facets/geo-distance-facet.html
+ */
+class GeoDistance extends AbstractFacet
+{
+ /**
+ * Sets the ranges for the facet all at once.
+ * Sample ranges:
+ * array (
+ * array('to' => 50),
+ * array('from' => 20, 'to' => 70),
+ * array('from' => 70, 'to' => 120),
+ * array('from' => 150)
+ * )
+ *
+ * @param array $ranges Numerical array with range definitions.
+ * @return \Elastica\Facet\GeoDistance
+ */
+ public function setRanges(array $ranges)
+ {
+ return $this->setParam('ranges', $ranges);
+ }
+
+ /**
+ * Set the relative GeoPoint for the facet.
+ *
+ * @param string $typeField index type and field e.g foo.bar
+ * @param float $latitude
+ * @param float $longitude
+ * @return \Elastica\Facet\GeoDistance
+ */
+ public function setGeoPoint($typeField, $latitude, $longitude)
+ {
+ return $this->setParam($typeField, array(
+ "lat" => $latitude,
+ "lon" => $longitude,
+ ));
+ }
+
+ /**
+ * Creates the full facet definition, which includes the basic
+ * facet definition of the parent.
+ *
+ * @see \Elastica\Facet\AbstractFacet::toArray()
+ * @throws \Elastica\Exception\InvalidException When the right fields haven't been set.
+ * @return array
+ */
+ public function toArray()
+ {
+ /**
+ * Set the geo_distance in the abstract as param.
+ */
+ $this->_setFacetParam ('geo_distance', $this->_params);
+
+ return parent::toArray();
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Facet/Histogram.php b/vendor/ruflin/elastica/lib/Elastica/Facet/Histogram.php
new file mode 100644
index 00000000..68be6757
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/Histogram.php
@@ -0,0 +1,90 @@
+<?php
+
+namespace Elastica\Facet;
+
+/**
+ * Implements the Histogram facet.
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Raul Martinez Jr <juneym@gmail.com>
+ * @link http://www.elasticsearch.org/guide/reference/api/search/facets/histogram-facet.html
+ */
+class Histogram extends AbstractFacet
+{
+ /**
+ * Sets the field for histogram
+ *
+ * @param string $field The name of the field for the histogram
+ * @return \Elastica\Facet\Histogram
+ */
+ public function setField($field)
+ {
+ return $this->setParam('field', $field);
+ }
+
+ /**
+ * Set the value for interval
+ *
+ * @param string $interval
+ * @return \Elastica\Facet\Histogram
+ */
+ public function setInterval($interval)
+ {
+ return $this->setParam('interval', $interval);
+ }
+
+ /**
+ * Set the fields for key_field and value_field
+ *
+ * @param string $keyField Key field
+ * @param string $valueField Value field
+ * @return \Elastica\Facet\Histogram
+ */
+ public function setKeyValueFields($keyField, $valueField)
+ {
+ return $this->setParam('key_field', $keyField)->setParam('value_field', $valueField);
+ }
+
+ /**
+ * Sets the key and value for this facet by script.
+ *
+ * @param string $keyScript Script to check whether it falls into the range.
+ * @param string $valueScript Script to use for statistical calculations.
+ * @return \Elastica\Facet\Histogram
+ */
+ public function setKeyValueScripts($keyScript, $valueScript)
+ {
+ return $this->setParam('key_script', $keyScript)
+ ->setParam('value_script', $valueScript);
+ }
+
+ /**
+ * Set the "params" essential to the a script
+ *
+ * @param array $params Associative array (key/value pair)
+ * @return \Elastica\Facet\Histogram
+ */
+ public function setScriptParams(array $params)
+ {
+ return $this->setParam('params', $params);
+ }
+
+ /**
+ * Creates the full facet definition, which includes the basic
+ * facet definition of the parent.
+ *
+ * @see \Elastica\Facet\AbstractFacet::toArray()
+ * @throws \Elastica\Exception\InvalidException When the right fields haven't been set.
+ * @return array
+ */
+ public function toArray()
+ {
+ /**
+ * Set the range in the abstract as param.
+ */
+ $this->_setFacetParam('histogram', $this->_params);
+
+ return parent::toArray();
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Facet/Query.php b/vendor/ruflin/elastica/lib/Elastica/Facet/Query.php
new file mode 100644
index 00000000..d43a2375
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/Query.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Elastica\Facet;
+
+use Elastica\Query\AbstractQuery;
+
+/**
+ * Query facet
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Nicolas Ruflin <spam@ruflin.com>
+ * @link http://www.elasticsearch.org/guide/reference/api/search/facets/query-facet.html
+ */
+class Query extends AbstractFacet
+{
+ /**
+ * Set the query for the facet.
+ *
+ * @param \Elastica\Query\AbstractQuery $query
+ * @return \Elastica\Facet\Query
+ */
+ public function setQuery(AbstractQuery $query)
+ {
+ return $this->_setFacetParam('query', $query->toArray());
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Facet/Range.php b/vendor/ruflin/elastica/lib/Elastica/Facet/Range.php
new file mode 100644
index 00000000..194f611a
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/Range.php
@@ -0,0 +1,138 @@
+<?php
+
+namespace Elastica\Facet;
+
+use Elastica\Exception\InvalidException;
+
+/**
+ * Implements the range facet.
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Jasper van Wanrooy <jasper@vanwanrooy.net>
+ * @link http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html
+ */
+class Range extends AbstractFacet
+{
+ /**
+ * Sets the field for the range.
+ *
+ * @param string $field The name of the field for range.
+ * @return \Elastica\Facet\Range
+ */
+ public function setField($field)
+ {
+ return $this->setParam('field', $field);
+ }
+
+ /**
+ * Sets the fields by their separate key and value fields.
+ *
+ * @param string $keyField The key_field param for the range.
+ * @param string $valueField The key_value param for the range.
+ * @return \Elastica\Facet\Range
+ */
+ public function setKeyValueFields($keyField, $valueField)
+ {
+ return $this->setParam('key_field', $keyField)
+ ->setParam('value_field', $valueField);
+ }
+
+ /**
+ * Sets the key and value for this facet by script.
+ *
+ * @param string $keyScript Script to check whether it falls into the range.
+ * @param string $valueScript Script to use for statistical calculations.
+ *
+ * @return \Elastica\Facet\Range
+ */
+ public function setKeyValueScripts($keyScript, $valueScript)
+ {
+ return $this->setParam('key_script', $keyScript)
+ ->setParam('value_script', $valueScript);
+ }
+
+ /**
+ * Sets the ranges for the facet all at once. Sample ranges:
+ * array (
+ * array('to' => 50),
+ * array('from' => 20, 'to' 70),
+ * array('from' => 70, 'to' => 120),
+ * array('from' => 150)
+ * )
+ *
+ * @param array $ranges Numerical array with range definitions.
+ * @return \Elastica\Facet\Range
+ */
+ public function setRanges(array $ranges)
+ {
+ return $this->setParam('ranges', $ranges);
+ }
+
+ /**
+ * Adds a range to the range facet.
+ *
+ * @param mixed $from The from for the range.
+ * @param mixed $to The to for the range.
+ * @return \Elastica\Facet\Range
+ */
+ public function addRange($from = null, $to = null)
+ {
+ if (!isset($this->_params['ranges']) || !is_array($this->_params['ranges'])) {
+ $this->_params['ranges'] = array();
+ }
+
+ $range = array();
+ if (isset($from)) {
+ $range['from'] = $from;
+ }
+ if (isset($to)) {
+ $range['to'] = $to;
+ }
+ $this->_params['ranges'][] = $range;
+
+ return $this;
+ }
+
+ /**
+ * Creates the full facet definition, which includes the basic
+ * facet definition of the parent.
+ *
+ * @see \Elastica\Facet\AbstractFacet::toArray()
+ * @throws \Elastica\Exception\InvalidException When the right fields haven't been set.
+ * @return array
+ */
+ public function toArray()
+ {
+ /**
+ * Check the facet for validity.
+ * There are three ways to set the key and value field for the range:
+ * - a single field for both key and value; or
+ * - separate fields for key and value; or
+ * - separate scripts for key and value.
+ */
+ $fieldTypesSet = 0;
+ if (isset($this->_params['field'])) {
+ $fieldTypesSet++;
+ }
+ if (isset($this->_params['key_field'])) {
+ $fieldTypesSet++;
+ }
+ if (isset($this->_params['key_script'])) {
+ $fieldTypesSet++;
+ }
+
+ if ($fieldTypesSet === 0) {
+ throw new InvalidException('Neither field, key_field nor key_script is set.');
+ } elseif ($fieldTypesSet > 1) {
+ throw new InvalidException('Either field, key_field and key_value or key_script and value_script should be set.');
+ }
+
+ /**
+ * Set the range in the abstract as param.
+ */
+ $this->_setFacetParam('range', $this->_params);
+
+ return parent::toArray();
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Facet/Statistical.php b/vendor/ruflin/elastica/lib/Elastica/Facet/Statistical.php
new file mode 100644
index 00000000..71507b8f
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/Statistical.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Elastica\Facet;
+
+/**
+ * Implements the statistical facet.
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Robert Katzki <robert@katzki.de>
+ * @link http://www.elasticsearch.org/guide/reference/api/search/facets/statistical-facet.html
+ */
+class Statistical extends AbstractFacet
+{
+ /**
+ * Sets the field for the statistical query.
+ *
+ * @param string $field The field name for the statistical query.
+ * @return \Elastica\Facet\Statistical
+ */
+ public function setField($field)
+ {
+ return $this->setParam('field', $field);
+ }
+
+ /**
+ * Sets multiple fields for the statistical query.
+ *
+ * @param array $fields Numerical array with the fields for the statistical query.
+ * @return \Elastica\Facet\Statistical
+ */
+ public function setFields(array $fields)
+ {
+ return $this->setParam('fields', $fields);
+ }
+
+ /**
+ * Sets a script to calculate statistical information
+ *
+ * @param string $script The script to do calculations on the statistical values
+ * @return \Elastica\Facet\Statistical
+ */
+ public function setScript($script)
+ {
+ return $this->setParam('script', $script);
+ }
+
+ /**
+ * Creates the full facet definition, which includes the basic
+ * facet definition of the parent.
+ *
+ * @see \Elastica\Facet\AbstractFacet::toArray()
+ * @return array
+ */
+ public function toArray()
+ {
+ $this->_setFacetParam('statistical', $this->_params);
+
+ return parent::toArray();
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Facet/Terms.php b/vendor/ruflin/elastica/lib/Elastica/Facet/Terms.php
new file mode 100644
index 00000000..c1dab800
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/Terms.php
@@ -0,0 +1,129 @@
+<?php
+
+namespace Elastica\Facet;
+
+use Elastica\Exception\InvalidException;
+use Elastica\Script;
+
+/**
+ * Implements the terms facet.
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Nicolas Ruflin <spam@ruflin.com>
+ * @author Jasper van Wanrooy <jasper@vanwanrooy.net>
+ * @link http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html
+ */
+class Terms extends AbstractFacet
+{
+ /**
+ * Holds the types of ordering which are allowed
+ * by Elasticsearch.
+ *
+ * @var array
+ */
+ protected $_orderTypes = array('count', 'term', 'reverse_count', 'reverse_term');
+
+ /**
+ * Sets the field for the terms.
+ *
+ * @param string $field The field name for the terms.
+ * @return \Elastica\Facet\Terms
+ */
+ public function setField($field)
+ {
+ return $this->setParam('field', $field);
+ }
+
+ /**
+ * Sets the script for the term.
+ *
+ * @param string $script The script for the term.
+ * @return \Elastica\Facet\Terms
+ */
+ public function setScript($script)
+ {
+ $script = Script::create($script);
+ foreach ($script->toArray() as $param => $value) {
+ $this->setParam($param, $value);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Sets multiple fields for the terms.
+ *
+ * @param array $fields Numerical array with the fields for the terms.
+ * @return \Elastica\Facet\Terms
+ */
+ public function setFields(array $fields)
+ {
+ return $this->setParam('fields', $fields);
+ }
+
+ /**
+ * Sets the flag to return all available terms. When they
+ * don't have a hit, they have a count of zero.
+ *
+ * @param bool $allTerms Flag to fetch all terms.
+ * @return \Elastica\Facet\Terms
+ */
+ public function setAllTerms($allTerms)
+ {
+ return $this->setParam('all_terms', (bool) $allTerms);
+ }
+
+ /**
+ * Sets the ordering type for this facet. Elasticsearch
+ * internal default is count.
+ *
+ * @param string $type The order type to set use for sorting of the terms.
+ * @throws \Elastica\Exception\InvalidException When an invalid order type was set.
+ * @return \Elastica\Facet\Terms
+ */
+ public function setOrder($type)
+ {
+ if (!in_array($type, $this->_orderTypes)) {
+ throw new InvalidException('Invalid order type: ' . $type);
+ }
+
+ return $this->setParam('order', $type);
+ }
+
+ /**
+ * Set an array with terms which are omitted in the search.
+ *
+ * @param array $exclude Numerical array which includes all terms which needs to be ignored.
+ * @return \Elastica\Facet\Terms
+ */
+ public function setExclude(array $exclude)
+ {
+ return $this->setParam('exclude', $exclude);
+ }
+
+ /**
+ * Sets the amount of terms to be returned.
+ *
+ * @param int $size The amount of terms to be returned.
+ * @return \Elastica\Facet\Terms
+ */
+ public function setSize($size)
+ {
+ return $this->setParam('size', (int) $size);
+ }
+
+ /**
+ * Creates the full facet definition, which includes the basic
+ * facet definition of the parent.
+ *
+ * @see \Elastica\Facet\AbstractFacet::toArray()
+ * @return array
+ */
+ public function toArray()
+ {
+ $this->_setFacetParam('terms', $this->_params);
+
+ return parent::toArray();
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Facet/TermsStats.php b/vendor/ruflin/elastica/lib/Elastica/Facet/TermsStats.php
new file mode 100644
index 00000000..61c6b39e
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/TermsStats.php
@@ -0,0 +1,103 @@
+<?php
+
+namespace Elastica\Facet;
+
+use Elastica\Exception\InvalidException;
+
+/**
+ * Implements the statistical facet on a per term basis.
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Tom Michaelis <tom.michaelis@gmail.com>
+ * @link http://www.elasticsearch.org/guide/reference/api/search/facets/terms-stats-facet.html
+ */
+class TermsStats extends AbstractFacet
+{
+
+ /**
+ * Holds the types of ordering which are allowed
+ * by Elasticsearch.
+ *
+ * @var array
+ */
+ protected $_orderTypes = array('term', 'reverse_term', 'count', 'reverse_count',
+ 'total', 'reverse_total', 'min', 'reverse_min', 'max', 'reverse_max', 'mean',
+ 'reverse_mean');
+
+ /**
+ * Sets the key field for the query.
+ *
+ * @param string $keyField The key field name for the query.
+ * @return \Elastica\Facet\TermsStats
+ */
+ public function setKeyField( $keyField )
+ {
+ return $this->setParam( 'key_field', $keyField );
+ }
+
+ /**
+ * Sets a script to calculate statistical information on a per term basis
+ *
+ * @param string $valueScript The script to do calculations on the statistical values
+ * @return \Elastica\Facet\TermsStats
+ */
+ public function setValueScript( $valueScript )
+ {
+ return $this->setParam( 'value_script', $valueScript );
+ }
+
+ /**
+ * Sets the ordering type for this facet. Elasticsearch
+ * internal default is count.
+ *
+ * @param string $type The order type to set use for sorting of the terms.
+ * @throws \Elastica\Exception\InvalidException When an invalid order type was set.
+ * @return \Elastica\Facet\TermsStats
+ */
+ public function setOrder($type)
+ {
+ if (!in_array($type, $this->_orderTypes)) {
+ throw new InvalidException('Invalid order type: ' . $type);
+ }
+
+ return $this->setParam('order', $type);
+ }
+
+ /**
+ * Sets a field to compute basic statistical results on
+ *
+ * @param string $valueField The field to compute statistical values for
+ * @return \Elastica\Facet\TermsStats
+ */
+ public function setValueField( $valueField )
+ {
+ return $this->setParam( 'value_field', $valueField );
+ }
+
+ /**
+ * Sets the amount of terms to be returned.
+ *
+ * @param int $size The amount of terms to be returned.
+ * @return \Elastica\Facet\Terms
+ */
+ public function setSize($size)
+ {
+ return $this->setParam('size', (int) $size);
+ }
+
+ /**
+ * Creates the full facet definition, which includes the basic
+ * facet definition of the parent.
+ *
+ * @see \Elastica\Facet\AbstractFacet::toArray()
+ * @return array
+ */
+ public function toArray()
+ {
+ $this->_setFacetParam( 'terms_stats', $this->_params );
+
+ return parent::toArray();
+ }
+
+}