summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation')
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/AvgTest.php38
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/BaseAggregationTest.php28
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/CardinalityTest.php38
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php43
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateRangeTest.php51
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ExtendedStatsTest.php43
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/FilterTest.php78
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php45
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeohashGridTest.php45
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GlobalAggregationTest.php27
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/HistogramTest.php45
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php56
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MaxTest.php72
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MinTest.php38
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MissingTest.php37
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/NestedTest.php62
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/RangeTest.php41
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php124
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/StatsTest.php42
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/SumTest.php38
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/TermsTest.php39
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ValueCountTest.php38
22 files changed, 1068 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/AvgTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/AvgTest.php
new file mode 100644
index 00000000..5c6fe13d
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/AvgTest.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\Avg;
+use Elastica\Document;
+use Elastica\Index;
+use Elastica\Query;
+
+class AvgTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex('avg');
+ $docs = array(
+ new Document('1', array('price' => 5)),
+ new Document('2', array('price' => 8)),
+ new Document('3', array('price' => 1)),
+ new Document('4', array('price' => 3)),
+ );
+ $this->_index->getType('test')->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testAvgAggregation()
+ {
+ $agg = new Avg("avg");
+ $agg->setField('price');
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregations();
+ $this->assertEquals((5 + 8 + 1 + 3) / 4.0, $results['avg']['value']);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/BaseAggregationTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/BaseAggregationTest.php
new file mode 100644
index 00000000..5569ca78
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/BaseAggregationTest.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Index;
+use Elastica\Test\Base;
+
+abstract class BaseAggregationTest extends Base
+{
+ /**
+ * @var Index
+ */
+ protected $_index;
+
+ protected function tearDown()
+ {
+ parent::tearDown();
+ if ($this->_index instanceof Index) {
+ $this->_index->delete();
+ }
+ }
+
+ protected function _createIndex($name = 'test', $delete = true, $shards = 1)
+ {
+ return parent::_createIndex('test_aggregation_' . $name, $delete, $shards);
+ }
+} \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/CardinalityTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/CardinalityTest.php
new file mode 100644
index 00000000..d2f4d2be
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/CardinalityTest.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\Cardinality;
+use Elastica\Document;
+use Elastica\Query;
+
+class CardinalityTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("cardinality");
+ $docs = array(
+ new Document("1", array("color" => "blue")),
+ new Document("2", array("color" => "blue")),
+ new Document("3", array("color" => "red")),
+ new Document("4", array("color" => "green")),
+ );
+ $this->_index->getType("test")->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testCardinalityAggregation()
+ {
+ $agg = new Cardinality("cardinality");
+ $agg->setField("color");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("cardinality");
+
+ $this->assertEquals(3, $results['value']);
+ }
+}
+
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php
new file mode 100644
index 00000000..d5bd878c
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\DateHistogram;
+use Elastica\Document;
+use Elastica\Query;
+use Elastica\Type\Mapping;
+
+class DateHistogramTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("date_histogram");
+ $mapping = new Mapping();
+ $mapping->setProperties(array(
+ "created" => array("type" => "date")
+ ));
+ $type = $this->_index->getType("test");
+ $type->setMapping($mapping);
+ $docs = array(
+ new Document("1", array("created" => 1390962135000)),
+ new Document("2", array("created" => 1390965735000)),
+ new Document("3", array("created" => 1390954935000)),
+ );
+ $type->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testDateHistogramAggregation()
+ {
+ $agg = new DateHistogram("hist", "created", "1h");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("hist");
+
+ $this->assertEquals(3, sizeof($results['buckets']));
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateRangeTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateRangeTest.php
new file mode 100644
index 00000000..781f2112
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateRangeTest.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\DateRange;
+use Elastica\Document;
+use Elastica\Query;
+use Elastica\Type\Mapping;
+
+class DateRangeTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("date_range");
+ $mapping = new Mapping();
+ $mapping->setProperties(array(
+ "created" => array("type" => "date")
+ ));
+ $type = $this->_index->getType("test");
+ $type->setMapping($mapping);
+ $docs = array(
+ new Document("1", array("created" => 1390962135000)),
+ new Document("2", array("created" => 1390965735000)),
+ new Document("3", array("created" => 1390954935000)),
+ );
+ $type->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testDateRangeAggregation()
+ {
+ $agg = new DateRange("date");
+ $agg->setField("created");
+ $agg->addRange(1390958535000)->addRange(null, 1390958535000);
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("date");
+
+ foreach ($results['buckets'] as $bucket) {
+ if (array_key_exists('to', $bucket)) {
+ $this->assertEquals(1, $bucket['doc_count']);
+ } else if (array_key_exists('from', $bucket)) {
+ $this->assertEquals(2, $bucket['doc_count']);
+ }
+ }
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ExtendedStatsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ExtendedStatsTest.php
new file mode 100644
index 00000000..e125c9c9
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ExtendedStatsTest.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\ExtendedStats;
+use Elastica\Document;
+use Elastica\Query;
+
+class ExtendedStatsTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("extended_stats");
+ $docs = array(
+ new Document("1", array("price" => 5)),
+ new Document("2", array("price" => 8)),
+ new Document("3", array("price" => 1)),
+ new Document("4", array("price" => 3)),
+ );
+ $this->_index->getType("test")->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testExtendedStatsAggregation()
+ {
+ $agg = new ExtendedStats("stats");
+ $agg->setField("price");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("stats");
+
+ $this->assertEquals(4, $results['count']);
+ $this->assertEquals(1, $results['min']);
+ $this->assertEquals(8, $results['max']);
+ $this->assertEquals((5 + 8 + 1 + 3) / 4.0, $results['avg']);
+ $this->assertEquals((5 + 8 + 1 + 3), $results['sum']);
+ $this->assertTrue(array_key_exists('sum_of_squares', $results));
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/FilterTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/FilterTest.php
new file mode 100644
index 00000000..dd4d4c2d
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/FilterTest.php
@@ -0,0 +1,78 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\Avg;
+use Elastica\Aggregation\Filter;
+use Elastica\Document;
+use Elastica\Filter\Range;
+use Elastica\Filter\Term;
+use Elastica\Query;
+
+class FilterTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("filter");
+ $docs = array(
+ new Document("1", array("price" => 5, "color" => "blue")),
+ new Document("2", array("price" => 8, "color" => "blue")),
+ new Document("3", array("price" => 1, "color" => "red")),
+ new Document("4", array("price" => 3, "color" => "green")),
+ );
+ $this->_index->getType("test")->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testToArray()
+ {
+ $expected = array(
+ "filter" => array("range" => array("stock" => array("gt" => 0))),
+ "aggs" => array(
+ "avg_price" => array("avg" => array("field" => "price"))
+ )
+ );
+
+ $agg = new Filter("in_stock_products");
+ $agg->setFilter(new Range("stock", array("gt" => 0)));
+ $avg = new Avg("avg_price");
+ $avg->setField("price");
+ $agg->addAggregation($avg);
+
+ $this->assertEquals($expected, $agg->toArray());
+ }
+
+ public function testFilterAggregation()
+ {
+ $agg = new Filter("filter");
+ $agg->setFilter(new Term(array("color" => "blue")));
+ $avg = new Avg("price");
+ $avg->setField("price");
+ $agg->addAggregation($avg);
+
+ $query = new Query();
+ $query->addAggregation($agg);
+
+ $results = $this->_index->search($query)->getAggregation("filter");
+ $results = $results['price']['value'];
+
+ $this->assertEquals((5 + 8) / 2.0, $results);
+ }
+
+ public function testFilterNoSubAggregation()
+ {
+ $agg = new Avg("price");
+ $agg->setField("price");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+
+ $results = $this->_index->search($query)->getAggregation("price");
+ $results = $results['value'];
+
+ $this->assertEquals((5 + 8 + 1 + 3) / 4.0, $results);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php
new file mode 100644
index 00000000..7fd677b1
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\GeoDistance;
+use Elastica\Document;
+use Elastica\Query;
+use Elastica\Type\Mapping;
+
+class GeoDistanceTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("geo_distance");
+ $mapping = new Mapping();
+ $mapping->setProperties(array(
+ "location" => array("type" => "geo_point")
+ ));
+ $type = $this->_index->getType("test");
+ $type->setMapping($mapping);
+ $docs = array(
+ new Document("1", array("location" => array("lat" => 32.849437, "lon" => -117.271732))),
+ new Document("2", array("location" => array("lat" => 32.798320, "lon" => -117.246648))),
+ new Document("3", array("location" => array("lat" => 37.782439, "lon" => -122.392560))),
+ );
+ $type->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testGeoDistanceAggregation()
+ {
+ $agg = new GeoDistance("geo", "location", array("lat" => 32.804654, "lon" => -117.242594));
+ $agg->addRange(null, 100);
+ $agg->setUnit("mi");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("geo");
+
+ $this->assertEquals(2, $results['buckets'][0]['doc_count']);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeohashGridTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeohashGridTest.php
new file mode 100644
index 00000000..38a047f7
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeohashGridTest.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\GeohashGrid;
+use Elastica\Document;
+use Elastica\Query;
+use Elastica\Type\Mapping;
+
+class GeohashGridTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("geohash_grid");
+ $mapping = new Mapping();
+ $mapping->setProperties(array(
+ "location" => array("type" => "geo_point")
+ ));
+ $type = $this->_index->getType("test");
+ $type->setMapping($mapping);
+ $docs = array(
+ new Document("1", array("location" => array("lat" => 32.849437, "lon" => -117.271732))),
+ new Document("2", array("location" => array("lat" => 32.798320, "lon" => -117.246648))),
+ new Document("3", array("location" => array("lat" => 37.782439, "lon" => -122.392560))),
+ );
+ $type->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testGeohashGridAggregation()
+ {
+ $agg = new GeohashGrid("hash", "location");
+ $agg->setPrecision(3);
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("hash");
+
+ $this->assertEquals(2, $results['buckets'][0]['doc_count']);
+ $this->assertEquals(1, $results['buckets'][1]['doc_count']);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GlobalAggregationTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GlobalAggregationTest.php
new file mode 100644
index 00000000..80366f50
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GlobalAggregationTest.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\Avg;
+use Elastica\Aggregation\GlobalAggregation;
+
+class GlobalAggregationTest extends BaseAggregationTest
+{
+ public function testToArray()
+ {
+ $expected = array(
+ "global" => new \stdClass(),
+ "aggs" => array(
+ "avg_price" => array("avg" => array("field" => "price"))
+ )
+ );
+
+ $agg = new GlobalAggregation("all_products");
+ $avg = new Avg("avg_price");
+ $avg->setField("price");
+ $agg->addAggregation($avg);
+ $this->assertEquals($expected, $agg->toArray());
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/HistogramTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/HistogramTest.php
new file mode 100644
index 00000000..35032f43
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/HistogramTest.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Document;
+use Elastica\Aggregation\Histogram;
+use Elastica\Query;
+
+class HistogramTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("histogram");
+ $docs = array(
+ new Document("1", array("price" => 5, "color" => "blue")),
+ new Document("2", array("price" => 8, "color" => "blue")),
+ new Document("3", array("price" => 1, "color" => "red")),
+ new Document("4", array("price" => 30, "color" => "green")),
+ new Document("5", array("price" => 40, "color" => "red")),
+ new Document("6", array("price" => 35, "color" => "green")),
+ new Document("7", array("price" => 42, "color" => "red")),
+ new Document("8", array("price" => 41, "color" => "blue")),
+ );
+ $this->_index->getType("test")->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testHistogramAggregation()
+ {
+ $agg = new Histogram("hist", "price", 10);
+ $agg->setMinimumDocumentCount(0); // should return empty buckets
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("hist");
+
+ $buckets = $results['buckets'];
+ $this->assertEquals(5, sizeof($buckets));
+ $this->assertEquals(30, $buckets[3]['key']);
+ $this->assertEquals(2, $buckets[3]['doc_count']);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php
new file mode 100644
index 00000000..fce6f857
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\IpRange;
+use Elastica\Document;
+use Elastica\Query;
+use Elastica\Type\Mapping;
+
+class IpRangeTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("ip_range");
+ $mapping = new Mapping();
+ $mapping->setProperties(array(
+ "address" => array("type" => "ip")
+ ));
+ $type = $this->_index->getType("test");
+ $type->setMapping($mapping);
+ $docs = array(
+ new Document("1", array("address" => "192.168.1.100")),
+ new Document("2", array("address" => "192.168.1.150")),
+ new Document("3", array("address" => "192.168.1.200")),
+ );
+ $type->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testIpRangeAggregation()
+ {
+ $agg = new IpRange("ip", "address");
+ $agg->addRange("192.168.1.101");
+ $agg->addRange(null, "192.168.1.200");
+
+ $cidrRange = "192.168.1.0/24";
+ $agg->addMaskRange($cidrRange);
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("ip");
+
+ foreach ($results['buckets'] as $bucket) {
+ if (array_key_exists('key', $bucket) && $bucket['key'] == $cidrRange) {
+ // the CIDR mask
+ $this->assertEquals(3, $bucket['doc_count']);
+ } else {
+ // the normal ip ranges
+ $this->assertEquals(2, $bucket['doc_count']);
+ }
+ }
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MaxTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MaxTest.php
new file mode 100644
index 00000000..0f5475b3
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MaxTest.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\Max;
+use Elastica\Document;
+use Elastica\Query;
+use Elastica\Script;
+
+class MaxTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex('max');
+ $docs = array(
+ new Document('1', array('price' => 5)),
+ new Document('2', array('price' => 8)),
+ new Document('3', array('price' => 1)),
+ new Document('4', array('price' => 3)),
+ );
+ $this->_index->getType('test')->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testToArray()
+ {
+ $expected = array(
+ "max" => array(
+ "field" => "price",
+ "script" => "_value * conversion_rate",
+ "params" => array(
+ "conversion_rate" => 1.2
+ )
+ ),
+ "aggs" => array(
+ "subagg" => array("max" => array("field" => "foo"))
+ )
+ );
+
+ $agg = new Max("min_price_in_euros");
+ $agg->setField("price");
+ $agg->setScript(new Script("_value * conversion_rate", array('conversion_rate' => 1.2)));
+ $max = new Max("subagg");
+ $max->setField("foo");
+ $agg->addAggregation($max);
+
+ $this->assertEquals($expected, $agg->toArray());
+ }
+
+ public function testMaxAggregation()
+ {
+ $agg = new Max("min_price");
+ $agg->setField("price");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("min_price");
+
+ $this->assertEquals(8, $results['value']);
+
+ // test using a script
+ $agg->setScript(new Script("_value * conversion_rate", array("conversion_rate" => 1.2)));
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("min_price");
+
+ $this->assertEquals(8 * 1.2, $results['value']);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MinTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MinTest.php
new file mode 100644
index 00000000..44b52fb4
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MinTest.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\Min;
+use Elastica\Document;
+use Elastica\Query;
+
+class MinTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex('min');
+ $docs = array(
+ new Document('1', array('price' => 5)),
+ new Document('2', array('price' => 8)),
+ new Document('3', array('price' => 1)),
+ new Document('4', array('price' => 3)),
+ );
+ $this->_index->getType('test')->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testMinAggregation()
+ {
+ $agg = new Min("min_price");
+ $agg->setField("price");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("min_price");
+
+ $this->assertEquals(1, $results['value']);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MissingTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MissingTest.php
new file mode 100644
index 00000000..2a852ed0
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MissingTest.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\Missing;
+use Elastica\Document;
+use Elastica\Query;
+
+class MissingTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex('missing');
+ $docs = array(
+ new Document('1', array('price' => 5, "color" => "blue")),
+ new Document('2', array('price' => 8, "color" => "blue")),
+ new Document('3', array('price' => 1)),
+ new Document('4', array('price' => 3, "color" => "green")),
+ );
+ $this->_index->getType('test')->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testMissingAggregation()
+ {
+ $agg = new Missing("missing", "color");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("missing");
+
+ $this->assertEquals(1, $results['doc_count']);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/NestedTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/NestedTest.php
new file mode 100644
index 00000000..ed6de99e
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/NestedTest.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\Min;
+use Elastica\Aggregation\Nested;
+use Elastica\Document;
+use Elastica\Query;
+use Elastica\Type\Mapping;
+
+class NestedTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("nested");
+ $mapping = new Mapping();
+ $mapping->setProperties(array(
+ "resellers" => array(
+ "type" => "nested",
+ "properties" => array(
+ "name" => array("type" => "string"),
+ "price" => array("type" => "double")
+ )
+ )
+ ));
+ $type = $this->_index->getType("test");
+ $type->setMapping($mapping);
+ $docs = array(
+ new Document("1", array(
+ "resellers" => array(
+ "name" => "spacely sprockets",
+ "price" => 5.55
+ )
+ )),
+ new Document("1", array(
+ "resellers" => array(
+ "name" => "cogswell cogs",
+ "price" => 4.98
+ )
+ ))
+ );
+ $type->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testNestedAggregation()
+ {
+ $agg = new Nested("resellers", "resellers");
+ $min = new Min("min_price");
+ $min->setField("price");
+ $agg->addAggregation($min);
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("resellers");
+
+ $this->assertEquals(4.98, $results['min_price']['value']);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/RangeTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/RangeTest.php
new file mode 100644
index 00000000..fb5ca2fe
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/RangeTest.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\Range;
+use Elastica\Document;
+use Elastica\Query;
+
+class RangeTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex('range');
+ $docs = array(
+ new Document('1', array('price' => 5)),
+ new Document('2', array('price' => 8)),
+ new Document('3', array('price' => 1)),
+ new Document('4', array('price' => 3)),
+ new Document('5', array('price' => 1.5)),
+ new Document('6', array('price' => 2)),
+ );
+ $this->_index->getType('test')->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testRangeAggregation()
+ {
+ $agg = new Range("range");
+ $agg->setField("price");
+ $agg->addRange(1.5, 5);
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("range");
+
+ $this->assertEquals(2, $results['buckets'][0]['doc_count']);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php
new file mode 100644
index 00000000..215dac63
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php
@@ -0,0 +1,124 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+use Elastica\Aggregation\Terms;
+use Elastica\Aggregation\Nested;
+use Elastica\Aggregation\ReverseNested;
+use Elastica\Document;
+use Elastica\Query;
+use Elastica\Type\Mapping;
+
+class ReverseNestedTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("nested");
+ $mapping = new Mapping();
+ $mapping->setProperties(array(
+ "comments" => array(
+ "type" => "nested",
+ "properties" => array(
+ "name" => array("type" => "string"),
+ "body" => array("type" => "string")
+ )
+ )
+ ));
+ $type = $this->_index->getType("test");
+ $type->setMapping($mapping);
+ $docs = array(
+ new Document("1", array(
+ "comments" => array(
+ array(
+ "name" => "bob",
+ "body" => "this is bobs comment",
+ ),
+ array(
+ "name" => "john",
+ "body" => "this is johns comment",
+ ),
+ ),
+ "tags" => array("foo", "bar"),
+ )),
+ new Document("2", array(
+ "comments" => array(
+ array(
+ "name" => "bob",
+ "body" => "this is another comment from bob",
+ ),
+ array(
+ "name" => "susan",
+ "body" => "this is susans comment",
+ ),
+ ),
+ "tags" => array("foo", "baz"),
+ ))
+ );
+ $type->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testPathNotSetIfNull()
+ {
+ $agg = new ReverseNested('nested');
+ $this->assertFalse($agg->hasParam('path'));
+ }
+
+ public function testPathSetIfNotNull()
+ {
+ $agg = new ReverseNested('nested', 'some_field');
+ $this->assertEquals('some_field', $agg->getParam('path'));
+ }
+
+ public function testReverseNestedAggregation()
+ {
+ $agg = new Nested("comments", "comments");
+ $names = new Terms("name");
+ $names->setField("comments.name");
+
+ $tags = new Terms("tags");
+ $tags->setField("tags");
+
+ $reverseNested = new ReverseNested("main");
+ $reverseNested->addAggregation($tags);
+
+ $names->addAggregation($reverseNested);
+
+ $agg->addAggregation($names);
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("comments");
+
+ $this->assertArrayHasKey('name', $results);
+ $nameResults = $results['name'];
+
+ $this->assertCount(3, $nameResults['buckets']);
+
+ // bob
+ $this->assertEquals('bob', $nameResults['buckets'][0]['key']);
+ $tags = array(
+ array('key' => 'foo', 'doc_count' => 2),
+ array('key' => 'bar', 'doc_count' => 1),
+ array('key' => 'baz', 'doc_count' => 1),
+ );
+ $this->assertEquals($tags, $nameResults['buckets'][0]['main']['tags']['buckets']);
+
+ // john
+ $this->assertEquals('john', $nameResults['buckets'][1]['key']);
+ $tags = array(
+ array('key' => 'bar', 'doc_count' => 1),
+ array('key' => 'foo', 'doc_count' => 1),
+ );
+ $this->assertEquals($tags, $nameResults['buckets'][1]['main']['tags']['buckets']);
+
+ // susan
+ $this->assertEquals('susan', $nameResults['buckets'][2]['key']);
+ $tags = array(
+ array('key' => 'baz', 'doc_count' => 1),
+ array('key' => 'foo', 'doc_count' => 1),
+ );
+ $this->assertEquals($tags, $nameResults['buckets'][2]['main']['tags']['buckets']);
+ }
+}
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/StatsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/StatsTest.php
new file mode 100644
index 00000000..2d315abf
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/StatsTest.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\Stats;
+use Elastica\Document;
+use Elastica\Query;
+
+class StatsTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex('stats');
+ $docs = array(
+ new Document('1', array('price' => 5)),
+ new Document('2', array('price' => 8)),
+ new Document('3', array('price' => 1)),
+ new Document('4', array('price' => 3)),
+ );
+ $this->_index->getType('test')->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testStatsAggregation()
+ {
+ $agg = new Stats("stats");
+ $agg->setField("price");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("stats");
+
+ $this->assertEquals(4, $results['count']);
+ $this->assertEquals(1, $results['min']);
+ $this->assertEquals(8, $results['max']);
+ $this->assertEquals((5 + 8 + 1 + 3) / 4.0, $results['avg']);
+ $this->assertEquals((5 + 8 + 1 + 3), $results['sum']);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/SumTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/SumTest.php
new file mode 100644
index 00000000..3b3c56a2
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/SumTest.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\Sum;
+use Elastica\Document;
+use Elastica\Query;
+
+class SumTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex('sum');
+ $docs = array(
+ new Document('1', array('price' => 5)),
+ new Document('2', array('price' => 8)),
+ new Document('3', array('price' => 1)),
+ new Document('4', array('price' => 3)),
+ );
+ $this->_index->getType('test')->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testSumAggregation()
+ {
+ $agg = new Sum("sum");
+ $agg->setField("price");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("sum");
+
+ $this->assertEquals(5 + 8 + 1 + 3, $results['value']);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/TermsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/TermsTest.php
new file mode 100644
index 00000000..d9f37a20
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/TermsTest.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\Terms;
+use Elastica\Document;
+use Elastica\Query;
+
+class TermsTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("terms");
+ $docs = array(
+ new Document("1", array("color" => "blue")),
+ new Document("2", array("color" => "blue")),
+ new Document("3", array("color" => "red")),
+ new Document("4", array("color" => "green")),
+ );
+ $this->_index->getType("test")->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testTermsAggregation()
+ {
+ $agg = new Terms("terms");
+ $agg->setField("color");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("terms");
+
+ $this->assertEquals(2, $results['buckets'][0]['doc_count']);
+ $this->assertEquals("blue", $results['buckets'][0]['key']);
+ }
+}
+ \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ValueCountTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ValueCountTest.php
new file mode 100644
index 00000000..5eba9ea4
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ValueCountTest.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+
+use Elastica\Aggregation\ValueCount;
+use Elastica\Document;
+use Elastica\Query;
+
+class ValueCountTest extends BaseAggregationTest
+{
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex('value_count');
+ $docs = array(
+ new Document('1', array('price' => 5)),
+ new Document('2', array('price' => 8)),
+ new Document('3', array('price' => 1)),
+ new Document('4', array('price' => 3)),
+ new Document('5', array('price' => 3)),
+ );
+ $this->_index->getType('test')->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ public function testValueCountAggregation()
+ {
+ $agg = new ValueCount("count", "price");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_index->search($query)->getAggregation("count");
+
+ $this->assertEquals(5, $results['value']);
+ }
+}
+ \ No newline at end of file