summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Facet
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-12-17 09:15:42 +0100
committerPierre Schmitz <pierre@archlinux.de>2015-12-17 09:44:51 +0100
commita1789ddde42033f1b05cc4929491214ee6e79383 (patch)
tree63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/ruflin/elastica/lib/Elastica/Facet
parent9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff)
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Facet')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/AbstractFacet.php145
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/DateHistogram.php58
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/Filter.php27
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/GeoCluster.php66
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/GeoDistance.php69
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/Histogram.php96
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/Query.php27
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/Range.php143
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/Statistical.php64
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/Terms.php137
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Facet/TermsStats.php107
11 files changed, 939 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..743cefe1
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/AbstractFacet.php
@@ -0,0 +1,145 @@
+<?php
+namespace Elastica\Facet;
+
+use Elastica\Exception\InvalidException;
+use Elastica\Filter\AbstractFilter;
+use Elastica\Param;
+
+/**
+ * Abstract facet object. Should be extended by all facet types.
+ *
+ * @author Nicolas Ruflin <spam@ruflin.com>
+ * @author Jasper van Wanrooy <jasper@vanwanrooy.net>
+ *
+ * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
+ */
+abstract class AbstractFacet extends Param
+{
+ /**
+ * @var string Holds the name of the facet.
+ */
+ protected $_name = '';
+
+ /**
+ * @var array Holds all facet parameters.
+ */
+ 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 If name is empty
+ *
+ * @return $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ public function setGlobal($global = true)
+ {
+ return $this->_setFacetParam('global', (bool) $global);
+ }
+
+ /**
+ * Sets the path to the nested document.
+ *
+ * @param string $nestedPath Nested path
+ *
+ * @return $this
+ */
+ public function setNested($nestedPath)
+ {
+ return $this->_setFacetParam('nested', $nestedPath);
+ }
+
+ /**
+ * Sets the scope.
+ *
+ * @param string $scope Scope
+ *
+ * @return $this
+ */
+ 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 $this
+ */
+ 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..c47eddab
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/DateHistogram.php
@@ -0,0 +1,58 @@
+<?php
+namespace Elastica\Facet;
+
+/**
+ * Implements the Date Histogram facet.
+ *
+ * @author Raul Martinez Jr <juneym@gmail.com>
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-facets-date-histogram-facet.html
+ * @link https://github.com/elasticsearch/elasticsearch/issues/591
+ * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
+ */
+class DateHistogram extends Histogram
+{
+ /**
+ * Set the time_zone parameter.
+ *
+ * @param string $tzOffset
+ *
+ * @return $this
+ */
+ public function setTimezone($tzOffset)
+ {
+ return $this->setParam('time_zone', $tzOffset);
+ }
+
+ /**
+ * Set the factor parameter.
+ *
+ * @param int $factor
+ *
+ * @return $this
+ */
+ public function setFactor($factor)
+ {
+ return $this->setParam('factor', $factor);
+ }
+
+ /**
+ * 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..26f032b4
--- /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.
+ *
+ * @author Nicolas Ruflin <spam@ruflin.com>
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-facets-filter-facet.html
+ * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
+ */
+class Filter extends AbstractFacet
+{
+ /**
+ * Set the filter for the facet.
+ *
+ * @param \Elastica\Filter\AbstractFilter $filter
+ *
+ * @return $this
+ */
+ 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..71fa5094
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/GeoCluster.php
@@ -0,0 +1,66 @@
+<?php
+namespace Elastica\Facet;
+
+/**
+ * Implements the Geo Cluster facet.
+ *
+ * @author Konstantin Nikiforov <konstantin.nikiforov@gmail.com>
+ *
+ * @link https://github.com/zenobase/geocluster-facet
+ * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
+ */
+class GeoCluster extends AbstractFacet
+{
+ /**
+ * @param string $fieldName
+ *
+ * @return $this
+ */
+ public function setField($fieldName)
+ {
+ $this->setParam('field', $fieldName);
+
+ return $this;
+ }
+
+ /**
+ * @param float $factor
+ *
+ * @return $this
+ */
+ public function setFactor($factor)
+ {
+ $this->setParam('factor', $factor);
+
+ return $this;
+ }
+
+ /**
+ * @param bool $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..664d33a6
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/GeoDistance.php
@@ -0,0 +1,69 @@
+<?php
+namespace Elastica\Facet;
+
+/**
+ * Implements the Geo Distance facet.
+ *
+ * @author Gerard A. Matthew <gerard.matthew@gmail.com>
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-facets-geo-distance-facet.html
+ * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
+ */
+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 $this
+ */
+ 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 $this
+ */
+ 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..1b76ea89
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/Histogram.php
@@ -0,0 +1,96 @@
+<?php
+namespace Elastica\Facet;
+
+/**
+ * Implements the Histogram facet.
+ *
+ * @author Raul Martinez Jr <juneym@gmail.com>
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-facets-histogram-facet.html
+ * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
+ */
+class Histogram extends AbstractFacet
+{
+ /**
+ * Sets the field for histogram.
+ *
+ * @param string $field The name of the field for the histogram
+ *
+ * @return $this
+ */
+ public function setField($field)
+ {
+ return $this->setParam('field', $field);
+ }
+
+ /**
+ * Set the value for interval.
+ *
+ * @param string $interval
+ *
+ * @return $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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..522090d5
--- /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.
+ *
+ * @author Nicolas Ruflin <spam@ruflin.com>
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-facets-query-facet.html
+ * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
+ */
+class Query extends AbstractFacet
+{
+ /**
+ * Set the query for the facet.
+ *
+ * @param \Elastica\Query\AbstractQuery $query
+ *
+ * @return $this
+ */
+ 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..f81caf3d
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/Range.php
@@ -0,0 +1,143 @@
+<?php
+namespace Elastica\Facet;
+
+use Elastica\Exception\InvalidException;
+
+/**
+ * Implements the range facet.
+ *
+ * @author Jasper van Wanrooy <jasper@vanwanrooy.net>
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-facets-range-facet.html
+ * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
+ */
+class Range extends AbstractFacet
+{
+ /**
+ * Sets the field for the range.
+ *
+ * @param string $field The name of the field for range.
+ *
+ * @return $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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..bb4eef8b
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/Statistical.php
@@ -0,0 +1,64 @@
+<?php
+namespace Elastica\Facet;
+
+/**
+ * Implements the statistical facet.
+ *
+ * @author Robert Katzki <robert@katzki.de>
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-facets-statistical-facet.html
+ * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
+ */
+class Statistical extends AbstractFacet
+{
+ /**
+ * Sets the field for the statistical query.
+ *
+ * @param string $field The field name for the statistical query.
+ *
+ * @return $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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..6af8867b
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/Terms.php
@@ -0,0 +1,137 @@
+<?php
+namespace Elastica\Facet;
+
+use Elastica\Exception\InvalidException;
+use Elastica\Script;
+
+/**
+ * Implements the terms facet.
+ *
+ * @author Nicolas Ruflin <spam@ruflin.com>
+ * @author Jasper van Wanrooy <jasper@vanwanrooy.net>
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-facets-terms-facet.html
+ * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
+ */
+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 $this
+ */
+ public function setField($field)
+ {
+ return $this->setParam('field', $field);
+ }
+
+ /**
+ * Sets the script for the term.
+ *
+ * @param string $script The script for the term.
+ *
+ * @return $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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..22d284c5
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Facet/TermsStats.php
@@ -0,0 +1,107 @@
+<?php
+namespace Elastica\Facet;
+
+use Elastica\Exception\InvalidException;
+
+/**
+ * Implements the statistical facet on a per term basis.
+ *
+ * @author Tom Michaelis <tom.michaelis@gmail.com>
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-facets-terms-stats-facet.html
+ * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
+ */
+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 $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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 $this
+ */
+ 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();
+ }
+}