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.php35
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/BaseAggregationTest.php22
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/CardinalityTest.php130
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php100
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateRangeTest.php45
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ExtendedStatsTest.php36
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/FilterTest.php95
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/FiltersTest.php120
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php43
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeohashGridTest.php41
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GlobalAggregationTest.php20
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/HistogramTest.php44
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php51
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MaxTest.php73
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MinTest.php36
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MissingTest.php34
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/NestedTest.php75
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/PercentilesTest.php125
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/RangeTest.php75
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php88
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptTest.php87
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptedMetricTest.php50
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/SignificantTermsTest.php72
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/StatsTest.php36
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/SumTest.php36
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/TermsTest.php38
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/TopHitsTest.php385
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ValueCountTest.php36
28 files changed, 1556 insertions, 472 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
index 5c6fe13d..650a4655 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/AvgTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/AvgTest.php
@@ -1,38 +1,39 @@
<?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()
+ protected function _getIndexForTest()
{
- 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();
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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)),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testAvgAggregation()
{
- $agg = new Avg("avg");
+ $agg = new Avg('avg');
$agg->setField('price');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregations();
+ $results = $this->_getIndexForTest()->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
index 5569ca78..48003d7e 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/BaseAggregationTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/BaseAggregationTest.php
@@ -1,28 +1,8 @@
<?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
index d2f4d2be..7bc383f0 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/CardinalityTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/CardinalityTest.php
@@ -1,38 +1,132 @@
<?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();
+ protected function _getIndexForTest()
+ {
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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')),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testCardinalityAggregation()
{
- $agg = new Cardinality("cardinality");
- $agg->setField("color");
+ $agg = new Cardinality('cardinality');
+ $agg->setField('color');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("cardinality");
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('cardinality');
$this->assertEquals(3, $results['value']);
}
+
+ /**
+ * @dataProvider invalidPrecisionThresholdProvider
+ * @expectedException \InvalidArgumentException
+ *
+ * @param $threshold
+ */
+ public function testInvalidPrecisionThreshold($threshold)
+ {
+ $agg = new Cardinality('threshold');
+ $agg->setPrecisionThreshold($threshold);
+ }
+
+ /**
+ * @dataProvider validPrecisionThresholdProvider
+ *
+ * @param $threshold
+ */
+ public function testPrecisionThreshold($threshold)
+ {
+ $agg = new Cardinality('threshold');
+ $agg->setPrecisionThreshold($threshold);
+
+ $this->assertNotNull($agg->getParam('precision_threshold'));
+ $this->assertInternalType('int', $agg->getParam('precision_threshold'));
+ }
+
+ public function invalidPrecisionThresholdProvider()
+ {
+ return array(
+ 'string' => array('100'),
+ 'float' => array(7.8),
+ 'boolean' => array(true),
+ 'array' => array(array()),
+ 'object' => array(new \StdClass()),
+ );
+ }
+
+ public function validPrecisionThresholdProvider()
+ {
+ return array(
+ 'negative-int' => array(-140),
+ 'zero' => array(0),
+ 'positive-int' => array(150),
+ 'more-than-max' => array(40001),
+ );
+ }
+
+ /**
+ * @dataProvider validRehashProvider
+ *
+ * @param bool $rehash
+ */
+ public function testRehash($rehash)
+ {
+ $agg = new Cardinality('rehash');
+ $agg->setRehash($rehash);
+
+ $this->assertNotNull($agg->getParam('rehash'));
+ $this->assertInternalType('boolean', $agg->getParam('rehash'));
+ }
+
+ /**
+ * @dataProvider invalidRehashProvider
+ * @expectedException \InvalidArgumentException
+ *
+ * @param mixed $rehash
+ */
+ public function testInvalidRehash($rehash)
+ {
+ $agg = new Cardinality('rehash');
+ $agg->setRehash($rehash);
+ }
+
+ public function invalidRehashProvider()
+ {
+ return array(
+ 'string' => array('100'),
+ 'int' => array(100),
+ 'float' => array(7.8),
+ 'array' => array(array()),
+ 'object' => array(new \StdClass()),
+ );
+ }
+
+ public function validRehashProvider()
+ {
+ return array(
+ 'true' => array(true),
+ 'false' => array(false),
+ );
+ }
}
-
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php
index d5bd878c..ca115ccc 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php
@@ -1,8 +1,6 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\DateHistogram;
use Elastica\Document;
use Elastica\Query;
@@ -10,34 +8,96 @@ use Elastica\Type\Mapping;
class DateHistogramTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- parent::setUp();
- $this->_index = $this->_createIndex("date_histogram");
- $mapping = new Mapping();
- $mapping->setProperties(array(
- "created" => array("type" => "date")
+ $index = $this->_createIndex();
+ $type = $index->getType('test');
+
+ $type->setMapping(new Mapping(null, array(
+ 'created' => array('type' => 'date'),
+ )));
+
+ $type->addDocuments(array(
+ new Document(1, array('created' => '2014-01-29T00:20:00')),
+ new Document(2, array('created' => '2014-01-29T02:20:00')),
+ new Document(3, array('created' => '2014-01-29T03:20:00')),
));
- $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();
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testDateHistogramAggregation()
{
- $agg = new DateHistogram("hist", "created", "1h");
+ $agg = new DateHistogram('hist', 'created', '1h');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("hist");
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('hist');
$this->assertEquals(3, sizeof($results['buckets']));
}
+
+ /**
+ * @group unit
+ */
+ public function testSetOffset()
+ {
+ $agg = new DateHistogram('hist', 'created', '1h');
+
+ $agg->setOffset('3m');
+
+ $expected = array(
+ 'date_histogram' => array(
+ 'field' => 'created',
+ 'interval' => '1h',
+ 'offset' => '3m',
+ ),
+ );
+
+ $this->assertEquals($expected, $agg->toArray());
+
+ $this->assertInstanceOf('Elastica\Aggregation\DateHistogram', $agg->setOffset('3m'));
+ }
+
+ /**
+ * @group functional
+ */
+ public function testSetOffsetWorks()
+ {
+ $agg = new DateHistogram('hist', 'created', '1m');
+ $agg->setOffset('+40s');
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('hist');
+
+ $this->assertEquals('2014-01-29T00:19:40.000Z', $results['buckets'][0]['key_as_string']);
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetTimezone()
+ {
+ $agg = new DateHistogram('hist', 'created', '1h');
+
+ $agg->setTimezone('-02:30');
+
+ $expected = array(
+ 'date_histogram' => array(
+ 'field' => 'created',
+ 'interval' => '1h',
+ 'time_zone' => '-02:30',
+ ),
+ );
+
+ $this->assertEquals($expected, $agg->toArray());
+
+ $this->assertInstanceOf('Elastica\Aggregation\DateHistogram', $agg->setTimezone('-02:30'));
+ }
}
- \ 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
index 781f2112..b8078a4c 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateRangeTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/DateRangeTest.php
@@ -1,8 +1,6 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\DateRange;
use Elastica\Document;
use Elastica\Query;
@@ -10,42 +8,45 @@ use Elastica\Type\Mapping;
class DateRangeTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- parent::setUp();
- $this->_index = $this->_createIndex("date_range");
- $mapping = new Mapping();
- $mapping->setProperties(array(
- "created" => array("type" => "date")
+ $index = $this->_createIndex();
+ $type = $index->getType('test');
+
+ $type->setMapping(new Mapping(null, array(
+ 'created' => array('type' => 'date'),
+ )));
+
+ $type->addDocuments(array(
+ new Document(1, array('created' => 1390962135000)),
+ new Document(2, array('created' => 1390965735000)),
+ new Document(3, array('created' => 1390954935000)),
));
- $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();
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testDateRangeAggregation()
{
- $agg = new DateRange("date");
- $agg->setField("created");
+ $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");
+ $results = $this->_getIndexForTest()->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)) {
+ } elseif (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
index e125c9c9..8c336245 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ExtendedStatsTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ExtendedStatsTest.php
@@ -1,36 +1,39 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\ExtendedStats;
use Elastica\Document;
use Elastica\Query;
class ExtendedStatsTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- 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();
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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)),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testExtendedStatsAggregation()
{
- $agg = new ExtendedStats("stats");
- $agg->setField("price");
+ $agg = new ExtendedStats('stats');
+ $agg->setField('price');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("stats");
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('stats');
$this->assertEquals(4, $results['count']);
$this->assertEquals(1, $results['min']);
@@ -40,4 +43,3 @@ class ExtendedStatsTest extends BaseAggregationTest
$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
index dd4d4c2d..9198bb95 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/FilterTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/FilterTest.php
@@ -1,8 +1,6 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\Avg;
use Elastica\Aggregation\Filter;
use Elastica\Document;
@@ -12,67 +10,104 @@ use Elastica\Query;
class FilterTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- 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();
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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')),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group unit
+ */
public function testToArray()
{
$expected = array(
- "filter" => array("range" => array("stock" => array("gt" => 0))),
- "aggs" => array(
- "avg_price" => array("avg" => array("field" => "price"))
- )
+ '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 = 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());
}
+ /**
+ * @group functional
+ */
public function testFilterAggregation()
{
- $agg = new Filter("filter");
- $agg->setFilter(new Term(array("color" => "blue")));
- $avg = new Avg("price");
- $avg->setField("price");
+ $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 = $this->_getIndexForTest()->search($query)->getAggregation('filter');
$results = $results['price']['value'];
$this->assertEquals((5 + 8) / 2.0, $results);
}
+ /**
+ * @group functional
+ */
public function testFilterNoSubAggregation()
{
- $agg = new Avg("price");
- $agg->setField("price");
+ $agg = new Avg('price');
+ $agg->setField('price');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("price");
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('price');
$results = $results['value'];
$this->assertEquals((5 + 8 + 1 + 3) / 4.0, $results);
}
+
+ /**
+ * @group unit
+ */
+ public function testConstruct()
+ {
+ $agg = new Filter('foo', new Term(array('color' => 'blue')));
+
+ $expected = array(
+ 'filter' => array(
+ 'term' => array(
+ 'color' => 'blue',
+ ),
+ ),
+ );
+
+ $this->assertEquals($expected, $agg->toArray());
+ }
+
+ /**
+ * @group unit
+ */
+ public function testConstructWithoutFilter()
+ {
+ $agg = new Filter('foo');
+ $this->assertEquals('foo', $agg->getName());
+ }
}
- \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/FiltersTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/FiltersTest.php
new file mode 100644
index 00000000..36ebcd45
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/FiltersTest.php
@@ -0,0 +1,120 @@
+<?php
+namespace Elastica\Test\Aggregation;
+
+use Elastica\Aggregation\Avg;
+use Elastica\Aggregation\Filter;
+use Elastica\Aggregation\Filters;
+use Elastica\Document;
+use Elastica\Filter\Term;
+use Elastica\Query;
+
+class FiltersTest extends BaseAggregationTest
+{
+ protected function _getIndexForTest()
+ {
+ $index = $this->_createIndex('filter');
+
+ $index->getType('test')->addDocuments(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')),
+ ));
+
+ $index->refresh();
+
+ return $index;
+ }
+
+ /**
+ * @group unit
+ */
+ public function testToArrayUsingNamedFilters()
+ {
+ $expected = array(
+ 'filters' => array(
+ 'filters' => array(
+ 'blue' => array(
+ 'term' => array('color' => 'blue'),
+ ),
+ 'red' => array(
+ 'term' => array('color' => 'red'),
+ ),
+ ),
+ ),
+ 'aggs' => array(
+ 'avg_price' => array('avg' => array('field' => 'price')),
+ ),
+ );
+
+ $agg = new Filters('by_color');
+ $agg->addFilter(new Term(array('color' => 'blue')), 'blue');
+ $agg->addFilter(new Term(array('color' => 'red')), 'red');
+
+ $avg = new Avg('avg_price');
+ $avg->setField('price');
+ $agg->addAggregation($avg);
+
+ $this->assertEquals($expected, $agg->toArray());
+ }
+
+ /**
+ * @group unit
+ */
+ public function testToArrayUsingAnonymousFilters()
+ {
+ $expected = array(
+ 'filters' => array(
+ 'filters' => array(
+ array(
+ 'term' => array('color' => 'blue'),
+ ),
+ array(
+ 'term' => array('color' => 'red'),
+ ),
+ ),
+ ),
+ 'aggs' => array(
+ 'avg_price' => array('avg' => array('field' => 'price')),
+ ),
+ );
+
+ $agg = new Filters('by_color');
+ $agg->addFilter(new Term(array('color' => 'blue')));
+ $agg->addFilter(new Term(array('color' => 'red')));
+
+ $avg = new Avg('avg_price');
+ $avg->setField('price');
+ $agg->addAggregation($avg);
+
+ $this->assertEquals($expected, $agg->toArray());
+ }
+
+ /**
+ * @group functional
+ */
+ public function testFilterAggregation()
+ {
+ $agg = new Filters('by_color');
+ $agg->addFilter(new Term(array('color' => 'blue')), 'blue');
+ $agg->addFilter(new Term(array('color' => 'red')), 'red');
+
+ $avg = new Avg('avg_price');
+ $avg->setField('price');
+ $agg->addAggregation($avg);
+
+ $query = new Query();
+ $query->addAggregation($agg);
+
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('by_color');
+
+ $resultsForBlue = $results['buckets']['blue'];
+ $resultsForRed = $results['buckets']['red'];
+
+ $this->assertEquals(2, $resultsForBlue['doc_count']);
+ $this->assertEquals(1, $resultsForRed['doc_count']);
+
+ $this->assertEquals((5 + 8) / 2, $resultsForBlue['avg_price']['value']);
+ $this->assertEquals(1, $resultsForRed['avg_price']['value']);
+ }
+}
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php
index 7fd677b1..f8a02d1d 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php
@@ -1,8 +1,6 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\GeoDistance;
use Elastica\Document;
use Elastica\Query;
@@ -10,36 +8,39 @@ use Elastica\Type\Mapping;
class GeoDistanceTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- parent::setUp();
- $this->_index = $this->_createIndex("geo_distance");
- $mapping = new Mapping();
- $mapping->setProperties(array(
- "location" => array("type" => "geo_point")
+ $index = $this->_createIndex();
+ $type = $index->getType('test');
+
+ $type->setMapping(new Mapping(null, array(
+ 'location' => array('type' => 'geo_point'),
+ )));
+
+ $type->addDocuments(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 = $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();
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testGeoDistanceAggregation()
{
- $agg = new GeoDistance("geo", "location", array("lat" => 32.804654, "lon" => -117.242594));
+ $agg = new GeoDistance('geo', 'location', array('lat' => 32.804654, 'lon' => -117.242594));
$agg->addRange(null, 100);
- $agg->setUnit("mi");
+ $agg->setUnit('mi');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("geo");
+ $results = $this->_getIndexForTest()->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
index 38a047f7..6e0d43fd 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeohashGridTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GeohashGridTest.php
@@ -1,8 +1,6 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\GeohashGrid;
use Elastica\Document;
use Elastica\Query;
@@ -10,36 +8,39 @@ use Elastica\Type\Mapping;
class GeohashGridTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- parent::setUp();
- $this->_index = $this->_createIndex("geohash_grid");
- $mapping = new Mapping();
- $mapping->setProperties(array(
- "location" => array("type" => "geo_point")
+ $index = $this->_createIndex();
+ $type = $index->getType('test');
+
+ $type->setMapping(new Mapping(null, array(
+ 'location' => array('type' => 'geo_point'),
+ )));
+
+ $type->addDocuments(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 = $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();
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testGeohashGridAggregation()
{
- $agg = new GeohashGrid("hash", "location");
+ $agg = new GeohashGrid('hash', 'location');
$agg->setPrecision(3);
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("hash");
+ $results = $this->_getIndexForTest()->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
index 80366f50..6ab086d0 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GlobalAggregationTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/GlobalAggregationTest.php
@@ -1,27 +1,27 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\Avg;
use Elastica\Aggregation\GlobalAggregation;
class GlobalAggregationTest extends BaseAggregationTest
{
+ /**
+ * @group unit
+ */
public function testToArray()
{
$expected = array(
- "global" => new \stdClass(),
- "aggs" => array(
- "avg_price" => array("avg" => array("field" => "price"))
- )
+ '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 = 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
index 35032f43..ffdf73a4 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/HistogramTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/HistogramTest.php
@@ -1,40 +1,43 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
-use Elastica\Document;
use Elastica\Aggregation\Histogram;
+use Elastica\Document;
use Elastica\Query;
class HistogramTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- 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();
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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')),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testHistogramAggregation()
{
- $agg = new Histogram("hist", "price", 10);
+ $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");
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('hist');
$buckets = $results['buckets'];
$this->assertEquals(5, sizeof($buckets));
@@ -42,4 +45,3 @@ class HistogramTest extends BaseAggregationTest
$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
index fce6f857..2f3099f6 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php
@@ -1,8 +1,6 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\IpRange;
use Elastica\Document;
use Elastica\Query;
@@ -10,38 +8,42 @@ use Elastica\Type\Mapping;
class IpRangeTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- parent::setUp();
- $this->_index = $this->_createIndex("ip_range");
- $mapping = new Mapping();
- $mapping->setProperties(array(
- "address" => array("type" => "ip")
+ $index = $this->_createIndex();
+ $type = $index->getType('test');
+
+ $type->setMapping(new Mapping(null, array(
+ 'address' => array('type' => 'ip'),
+ )));
+
+ $type->addDocuments(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 = $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();
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
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 = 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");
-
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('ip');
+
foreach ($results['buckets'] as $bucket) {
if (array_key_exists('key', $bucket) && $bucket['key'] == $cidrRange) {
// the CIDR mask
@@ -53,4 +55,3 @@ class IpRangeTest extends BaseAggregationTest
}
}
}
- \ 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
index 0f5475b3..f057b81d 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MaxTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MaxTest.php
@@ -1,8 +1,6 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\Max;
use Elastica\Document;
use Elastica\Query;
@@ -10,63 +8,72 @@ use Elastica\Script;
class MaxTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- 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();
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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)),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group unit
+ */
public function testToArray()
{
$expected = array(
- "max" => array(
- "field" => "price",
- "script" => "_value * conversion_rate",
- "params" => array(
- "conversion_rate" => 1.2
- )
+ 'max' => array(
+ 'field' => 'price',
+ 'script' => '_value * conversion_rate',
+ 'params' => array(
+ 'conversion_rate' => 1.2,
+ ),
+ ),
+ 'aggs' => array(
+ 'subagg' => array('max' => array('field' => 'foo')),
),
- "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 = 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());
}
+ /**
+ * @group functional
+ */
public function testMaxAggregation()
{
- $agg = new Max("min_price");
- $agg->setField("price");
+ $index = $this->_getIndexForTest();
+
+ $agg = new Max('min_price');
+ $agg->setField('price');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("min_price");
+ $results = $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)));
+ $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");
+ $results = $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
index 44b52fb4..ce0ad5e7 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MinTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MinTest.php
@@ -1,38 +1,40 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\Min;
use Elastica\Document;
use Elastica\Query;
class MinTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- 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();
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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)),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testMinAggregation()
{
- $agg = new Min("min_price");
- $agg->setField("price");
+ $agg = new Min('min_price');
+ $agg->setField('price');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("min_price");
+ $results = $this->_getIndexForTest()->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
index 2a852ed0..85461879 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MissingTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/MissingTest.php
@@ -1,37 +1,39 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\Missing;
use Elastica\Document;
use Elastica\Query;
class MissingTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- 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();
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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')),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testMissingAggregation()
{
- $agg = new Missing("missing", "color");
+ $agg = new Missing('missing', 'color');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("missing");
+ $results = $this->_getIndexForTest()->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
index ed6de99e..58c5d13a 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/NestedTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/NestedTest.php
@@ -1,8 +1,6 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\Min;
use Elastica\Aggregation\Nested;
use Elastica\Document;
@@ -11,52 +9,55 @@ use Elastica\Type\Mapping;
class NestedTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- 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
- )
+ $index = $this->_createIndex();
+ $type = $index->getType('test');
+
+ $type->setMapping(new Mapping(null, array(
+ 'resellers' => array(
+ 'type' => 'nested',
+ 'properties' => array(
+ 'name' => array('type' => 'string'),
+ 'price' => array('type' => 'double'),
+ ),
+ ),
+ )));
+
+ $type->addDocuments(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();
+ new Document(2, array(
+ 'resellers' => array(
+ 'name' => 'cogswell cogs',
+ 'price' => 4.98,
+ ),
+ )),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testNestedAggregation()
{
- $agg = new Nested("resellers", "resellers");
- $min = new Min("min_price");
- $min->setField("price");
+ $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");
+ $results = $this->_getIndexForTest()->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/PercentilesTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/PercentilesTest.php
new file mode 100644
index 00000000..ee4dd2c5
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/PercentilesTest.php
@@ -0,0 +1,125 @@
+<?php
+namespace Elastica\Test\Aggregation;
+
+use Elastica\Aggregation\Percentiles;
+use Elastica\Document;
+use Elastica\Query;
+
+class PercentilesTest extends BaseAggregationTest
+{
+ /**
+ * @group functional
+ */
+ public function testConstruct()
+ {
+ $aggr = new Percentiles('price_percentile');
+ $this->assertEquals('price_percentile', $aggr->getName());
+
+ $aggr = new Percentiles('price_percentile', 'price');
+ $this->assertEquals('price', $aggr->getParam('field'));
+ }
+
+ /**
+ * @group functional
+ */
+ public function testSetField()
+ {
+ $aggr = new Percentiles('price_percentile');
+ $aggr->setField('price');
+
+ $this->assertEquals('price', $aggr->getParam('field'));
+ $this->assertInstanceOf('Elastica\Aggregation\Percentiles', $aggr->setField('price'));
+ }
+
+ /**
+ * @group functional
+ */
+ public function testSetCompression()
+ {
+ $aggr = new Percentiles('price_percentile');
+ $aggr->setCompression(200);
+ $this->assertEquals(200, $aggr->getParam('compression'));
+ $this->assertInstanceOf('Elastica\Aggregation\Percentiles', $aggr->setCompression(200));
+ }
+
+ /**
+ * @group functional
+ */
+ public function testSetPercents()
+ {
+ $percents = array(1, 2, 3);
+ $aggr = new Percentiles('price_percentile');
+ $aggr->setPercents($percents);
+ $this->assertEquals($percents, $aggr->getParam('percents'));
+ $this->assertInstanceOf('Elastica\Aggregation\Percentiles', $aggr->setPercents($percents));
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAddPercent()
+ {
+ $percents = array(1, 2, 3);
+ $aggr = new Percentiles('price_percentile');
+ $aggr->setPercents($percents);
+ $this->assertEquals($percents, $aggr->getParam('percents'));
+ $aggr->addPercent(4);
+ $percents[] = 4;
+ $this->assertEquals($percents, $aggr->getParam('percents'));
+ $this->assertInstanceOf('Elastica\Aggregation\Percentiles', $aggr->addPercent(4));
+ }
+
+ /**
+ * @group functional
+ */
+ public function testSetScript()
+ {
+ $script = 'doc["load_time"].value / 20';
+ $aggr = new Percentiles('price_percentile');
+ $aggr->setScript($script);
+ $this->assertEquals($script, $aggr->getParam('script'));
+ $this->assertInstanceOf('Elastica\Aggregation\Percentiles', $aggr->setScript($script));
+ }
+
+ /**
+ * @group functional
+ */
+ public function testActualWork()
+ {
+ // prepare
+ $index = $this->_createIndex();
+ $type = $index->getType('offer');
+ $type->addDocuments(array(
+ new Document(1, array('price' => 100)),
+ new Document(2, array('price' => 200)),
+ new Document(3, array('price' => 300)),
+ new Document(4, array('price' => 400)),
+ new Document(5, array('price' => 500)),
+ new Document(6, array('price' => 600)),
+ new Document(7, array('price' => 700)),
+ new Document(8, array('price' => 800)),
+ new Document(9, array('price' => 900)),
+ new Document(10, array('price' => 1000)),
+ ));
+ $index->refresh();
+
+ // execute
+ $aggr = new Percentiles('price_percentile');
+ $aggr->setField('price');
+
+ $query = new Query();
+ $query->addAggregation($aggr);
+
+ $resultSet = $type->search($query);
+ $aggrResult = $resultSet->getAggregation('price_percentile');
+
+ // hope it's ok to hardcode results...
+ $this->assertEquals(109.0, $aggrResult['values']['1.0']);
+ $this->assertEquals(145.0, $aggrResult['values']['5.0']);
+ $this->assertEquals(325.0, $aggrResult['values']['25.0']);
+ $this->assertEquals(550.0, $aggrResult['values']['50.0']);
+ $this->assertEquals(775.0, $aggrResult['values']['75.0']);
+ $this->assertEquals(955.0, $aggrResult['values']['95.0']);
+ $this->assertEquals(991.0, $aggrResult['values']['99.0']);
+ }
+}
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/RangeTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/RangeTest.php
index fb5ca2fe..f96e4096 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/RangeTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/RangeTest.php
@@ -1,41 +1,78 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\Range;
use Elastica\Document;
use Elastica\Query;
class RangeTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- 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();
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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)),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testRangeAggregation()
{
- $agg = new Range("range");
- $agg->setField("price");
+ $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");
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('range');
$this->assertEquals(2, $results['buckets'][0]['doc_count']);
}
+
+ /**
+ * @group unit
+ */
+ public function testRangeAggregationWithKey()
+ {
+ $agg = new Range('range');
+ $agg->setField('price');
+ $agg->addRange(null, 50, 'cheap');
+ $agg->addRange(50, 100, 'average');
+ $agg->addRange(100, null, 'expensive');
+
+ $expected = array(
+ 'range' => array(
+ 'field' => 'price',
+ 'ranges' => array(
+ array(
+ 'to' => 50,
+ 'key' => 'cheap',
+ ),
+ array(
+ 'from' => 50,
+ 'to' => 100,
+ 'key' => 'average',
+ ),
+ array(
+ 'from' => 100,
+ 'key' => 'expensive',
+ ),
+ ),
+ ),
+ );
+
+ $this->assertEquals($expected, $agg->toArray());
+ }
}
- \ 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
index 215dac63..0e2ed2e6 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php
@@ -1,86 +1,96 @@
<?php
-
namespace Elastica\Test\Aggregation;
-use Elastica\Aggregation\Terms;
use Elastica\Aggregation\Nested;
use Elastica\Aggregation\ReverseNested;
+use Elastica\Aggregation\Terms;
use Elastica\Document;
use Elastica\Query;
use Elastica\Type\Mapping;
class ReverseNestedTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- parent::setUp();
- $this->_index = $this->_createIndex("nested");
+ $index = $this->_createIndex();
$mapping = new Mapping();
$mapping->setProperties(array(
- "comments" => array(
- "type" => "nested",
- "properties" => array(
- "name" => array("type" => "string"),
- "body" => array("type" => "string")
- )
- )
+ 'comments' => array(
+ 'type' => 'nested',
+ 'properties' => array(
+ 'name' => array('type' => 'string'),
+ 'body' => array('type' => 'string'),
+ ),
+ ),
));
- $type = $this->_index->getType("test");
+ $type = $index->getType('test');
$type->setMapping($mapping);
- $docs = array(
- new Document("1", array(
- "comments" => array(
+
+ $type->addDocuments(array(
+ new Document(1, array(
+ 'comments' => array(
array(
- "name" => "bob",
- "body" => "this is bobs comment",
+ 'name' => 'bob',
+ 'body' => 'this is bobs comment',
),
array(
- "name" => "john",
- "body" => "this is johns comment",
+ 'name' => 'john',
+ 'body' => 'this is johns comment',
),
),
- "tags" => array("foo", "bar"),
+ 'tags' => array('foo', 'bar'),
)),
- new Document("2", array(
- "comments" => array(
+ new Document(2, array(
+ 'comments' => array(
array(
- "name" => "bob",
- "body" => "this is another comment from bob",
+ 'name' => 'bob',
+ 'body' => 'this is another comment from bob',
),
array(
- "name" => "susan",
- "body" => "this is susans comment",
+ 'name' => 'susan',
+ 'body' => 'this is susans comment',
),
),
- "tags" => array("foo", "baz"),
- ))
- );
- $type->addDocuments($docs);
- $this->_index->refresh();
+ 'tags' => array('foo', 'baz'),
+ )),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group unit
+ */
public function testPathNotSetIfNull()
{
$agg = new ReverseNested('nested');
$this->assertFalse($agg->hasParam('path'));
}
+ /**
+ * @group unit
+ */
public function testPathSetIfNotNull()
{
$agg = new ReverseNested('nested', 'some_field');
$this->assertEquals('some_field', $agg->getParam('path'));
}
+ /**
+ * @group functional
+ */
public function testReverseNestedAggregation()
{
- $agg = new Nested("comments", "comments");
- $names = new Terms("name");
- $names->setField("comments.name");
+ $agg = new Nested('comments', 'comments');
+ $names = new Terms('name');
+ $names->setField('comments.name');
- $tags = new Terms("tags");
- $tags->setField("tags");
+ $tags = new Terms('tags');
+ $tags->setField('tags');
- $reverseNested = new ReverseNested("main");
+ $reverseNested = new ReverseNested('main');
$reverseNested->addAggregation($tags);
$names->addAggregation($reverseNested);
@@ -89,7 +99,7 @@ class ReverseNestedTest extends BaseAggregationTest
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("comments");
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('comments');
$this->assertArrayHasKey('name', $results);
$nameResults = $results['name'];
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptTest.php
new file mode 100644
index 00000000..bf32b251
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptTest.php
@@ -0,0 +1,87 @@
+<?php
+namespace Elastica\Test\Aggregation;
+
+use Elastica\Aggregation\Sum;
+use Elastica\Document;
+use Elastica\Query;
+use Elastica\Script;
+
+class ScriptTest extends BaseAggregationTest
+{
+ protected function _getIndexForTest()
+ {
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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)),
+ ));
+
+ $index->refresh();
+
+ return $index;
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAggregationScript()
+ {
+ $agg = new Sum('sum');
+ // x = (0..1) is groovy-specific syntax, to see if lang is recognized
+ $script = new Script("x = (0..1); return doc['price'].value", null, 'groovy');
+ $agg->setScript($script);
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('sum');
+
+ $this->assertEquals(5 + 8 + 1 + 3, $results['value']);
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAggregationScriptAsString()
+ {
+ $agg = new Sum('sum');
+ $agg->setScript("doc['price'].value");
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('sum');
+
+ $this->assertEquals(5 + 8 + 1 + 3, $results['value']);
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetScript()
+ {
+ $aggregation = 'sum';
+ $string = "doc['price'].value";
+ $params = array(
+ 'param1' => 'one',
+ 'param2' => 1,
+ );
+ $lang = 'groovy';
+
+ $agg = new Sum($aggregation);
+ $script = new Script($string, $params, $lang);
+ $agg->setScript($script);
+
+ $array = $agg->toArray();
+
+ $expected = array(
+ $aggregation => array(
+ 'script' => $string,
+ 'params' => $params,
+ 'lang' => $lang,
+ ),
+ );
+ $this->assertEquals($expected, $array);
+ }
+}
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptedMetricTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptedMetricTest.php
new file mode 100644
index 00000000..31f5798b
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptedMetricTest.php
@@ -0,0 +1,50 @@
+<?php
+namespace Elastica\Test\Aggregation;
+
+use Elastica\Aggregation\ScriptedMetric;
+use Elastica\Document;
+use Elastica\Query;
+use Elastica\Type\Mapping;
+
+class ScriptedMetricTest extends BaseAggregationTest
+{
+ protected function _getIndexForTest()
+ {
+ $index = $this->_createIndex();
+ $type = $index->getType('test');
+
+ $type->setMapping(new Mapping(null, array(
+ 'start' => array('type' => 'long'),
+ 'end' => array('type' => 'long'),
+ )));
+
+ $type->addDocuments(array(
+ new Document(1, array('start' => 100, 'end' => 200)),
+ new Document(2, array('start' => 200, 'end' => 250)),
+ new Document(3, array('start' => 300, 'end' => 450)),
+ ));
+
+ $index->refresh();
+
+ return $index;
+ }
+
+ /**
+ * @group functional
+ */
+ public function testScriptedMetricAggregation()
+ {
+ $agg = new ScriptedMetric(
+ 'scripted',
+ "_agg['durations'] = [:]",
+ "key = doc['start'].value+ \":\"+ doc['end'].value; _agg.durations[key] = doc['end'].value - doc['start'].value;",
+ 'values = []; for (item in _agg.durations) { values.add(item.value) }; return values'
+ );
+
+ $query = new Query();
+ $query->addAggregation($agg);
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('scripted');
+
+ $this->assertEquals(array(100, 50, 150), $results['value'][0]);
+ }
+}
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/SignificantTermsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/SignificantTermsTest.php
new file mode 100644
index 00000000..8960768b
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/SignificantTermsTest.php
@@ -0,0 +1,72 @@
+<?php
+namespace Elastica\Test\Aggregation;
+
+use Elastica\Aggregation\SignificantTerms;
+use Elastica\Document;
+use Elastica\Filter\Terms as TermsFilter;
+use Elastica\Query;
+use Elastica\Query\Terms;
+
+class SignificantTermsTest extends BaseAggregationTest
+{
+ protected function _getIndexForTest()
+ {
+ $index = $this->_createIndex();
+ $colors = array('blue', 'blue', 'red', 'red', 'green', 'yellow', 'white', 'cyan', 'magenta');
+ $temperatures = array(1500, 1500, 1500, 1500, 2500, 3500, 4500, 5500, 6500, 7500, 7500, 8500, 9500);
+ $docs = array();
+ for ($i = 0;$i < 250;$i++) {
+ $docs[] = new Document($i, array('color' => $colors[$i % count($colors)], 'temperature' => $temperatures[$i % count($temperatures)]));
+ }
+ $index->getType('test')->addDocuments($docs);
+ $index->refresh();
+
+ return $index;
+ }
+
+ /**
+ * @group functional
+ */
+ public function testSignificantTermsAggregation()
+ {
+ $agg = new SignificantTerms('significantTerms');
+ $agg->setField('temperature');
+ $agg->setSize(1);
+
+ $termsQuery = new Terms();
+ $termsQuery->setTerms('color', array('blue', 'red', 'green', 'yellow', 'white'));
+
+ $query = new Query($termsQuery);
+ $query->addAggregation($agg);
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('significantTerms');
+
+ $this->assertEquals(1, count($results['buckets']));
+ $this->assertEquals(63, $results['buckets'][0]['doc_count']);
+ $this->assertEquals(79, $results['buckets'][0]['bg_count']);
+ $this->assertEquals('1500', $results['buckets'][0]['key_as_string']);
+ }
+
+ /**
+ * @group functional
+ */
+ public function testSignificantTermsAggregationWithBackgroundFilter()
+ {
+ $agg = new SignificantTerms('significantTerms');
+ $agg->setField('temperature');
+ $agg->setSize(1);
+ $termsFilter = new TermsFilter();
+ $termsFilter->setTerms('color', array('blue', 'red', 'green', 'yellow'));
+ $agg->setBackgroundFilter($termsFilter);
+
+ $termsQuery = new Terms();
+ $termsQuery->setTerms('color', array('blue', 'red', 'green', 'yellow', 'white'));
+
+ $query = new Query($termsQuery);
+ $query->addAggregation($agg);
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('significantTerms');
+
+ $this->assertEquals(15, $results['buckets'][0]['doc_count']);
+ $this->assertEquals(12, $results['buckets'][0]['bg_count']);
+ $this->assertEquals('4500', $results['buckets'][0]['key_as_string']);
+ }
+}
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/StatsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/StatsTest.php
index 2d315abf..45c9d08c 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/StatsTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/StatsTest.php
@@ -1,36 +1,39 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\Stats;
use Elastica\Document;
use Elastica\Query;
class StatsTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- 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();
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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)),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testStatsAggregation()
{
- $agg = new Stats("stats");
- $agg->setField("price");
+ $agg = new Stats('stats');
+ $agg->setField('price');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("stats");
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('stats');
$this->assertEquals(4, $results['count']);
$this->assertEquals(1, $results['min']);
@@ -39,4 +42,3 @@ class StatsTest extends BaseAggregationTest
$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
index 3b3c56a2..b60e6e14 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/SumTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/SumTest.php
@@ -1,38 +1,40 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\Sum;
use Elastica\Document;
use Elastica\Query;
class SumTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- 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();
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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)),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testSumAggregation()
{
- $agg = new Sum("sum");
- $agg->setField("price");
+ $agg = new Sum('sum');
+ $agg->setField('price');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("sum");
+ $results = $this->_getIndexForTest()->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
index d9f37a20..58eb02c2 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/TermsTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/TermsTest.php
@@ -1,39 +1,41 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\Terms;
use Elastica\Document;
use Elastica\Query;
class TermsTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- 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();
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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')),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testTermsAggregation()
{
- $agg = new Terms("terms");
- $agg->setField("color");
+ $agg = new Terms('terms');
+ $agg->setField('color');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("terms");
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('terms');
$this->assertEquals(2, $results['buckets'][0]['doc_count']);
- $this->assertEquals("blue", $results['buckets'][0]['key']);
+ $this->assertEquals('blue', $results['buckets'][0]['key']);
}
}
- \ No newline at end of file
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/TopHitsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/TopHitsTest.php
new file mode 100644
index 00000000..afe23e27
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/TopHitsTest.php
@@ -0,0 +1,385 @@
+<?php
+namespace Elastica\Test\Aggregation;
+
+use Elastica\Aggregation\Terms;
+use Elastica\Aggregation\TopHits;
+use Elastica\Document;
+use Elastica\Query;
+use Elastica\Query\MatchAll;
+use Elastica\Query\SimpleQueryString;
+use Elastica\Script;
+use Elastica\ScriptFields;
+
+class TopHitsTest extends BaseAggregationTest
+{
+ protected function _getIndexForTest()
+ {
+ $index = $this->_createIndex();
+
+ $index->getType('questions')->addDocuments(array(
+ new Document(1, array(
+ 'tags' => array('linux'),
+ 'last_activity_date' => '2015-01-05',
+ 'title' => 'Question about linux #1',
+ )),
+ new Document(2, array(
+ 'tags' => array('linux'),
+ 'last_activity_date' => '2014-12-23',
+ 'title' => 'Question about linux #2',
+ )),
+ new Document(3, array(
+ 'tags' => array('windows'),
+ 'last_activity_date' => '2015-01-05',
+ 'title' => 'Question about windows #1',
+ )),
+ new Document(4, array(
+ 'tags' => array('windows'),
+ 'last_activity_date' => '2014-12-23',
+ 'title' => 'Question about windows #2',
+ )),
+ new Document(5, array(
+ 'tags' => array('osx', 'apple'),
+ 'last_activity_date' => '2014-12-23',
+ 'title' => 'Question about osx',
+ )),
+ ));
+
+ $index->refresh();
+
+ return $index;
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetSize()
+ {
+ $agg = new TopHits('agg_name');
+ $returnValue = $agg->setSize(12);
+ $this->assertEquals(12, $agg->getParam('size'));
+ $this->assertInstanceOf('Elastica\Aggregation\TopHits', $returnValue);
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetFrom()
+ {
+ $agg = new TopHits('agg_name');
+ $returnValue = $agg->setFrom(12);
+ $this->assertEquals(12, $agg->getParam('from'));
+ $this->assertInstanceOf('Elastica\Aggregation\TopHits', $returnValue);
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetSort()
+ {
+ $sort = array('last_activity_date' => array('order' => 'desc'));
+ $agg = new TopHits('agg_name');
+ $returnValue = $agg->setSort($sort);
+ $this->assertEquals($sort, $agg->getParam('sort'));
+ $this->assertInstanceOf('Elastica\Aggregation\TopHits', $returnValue);
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetSource()
+ {
+ $fields = array('title', 'tags');
+ $agg = new TopHits('agg_name');
+ $returnValue = $agg->setSource($fields);
+ $this->assertEquals($fields, $agg->getParam('_source'));
+ $this->assertInstanceOf('Elastica\Aggregation\TopHits', $returnValue);
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetVersion()
+ {
+ $agg = new TopHits('agg_name');
+ $returnValue = $agg->setVersion(true);
+ $this->assertTrue($agg->getParam('version'));
+ $this->assertInstanceOf('Elastica\Aggregation\TopHits', $returnValue);
+
+ $agg->setVersion(false);
+ $this->assertFalse($agg->getParam('version'));
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetExplain()
+ {
+ $agg = new TopHits('agg_name');
+ $returnValue = $agg->setExplain(true);
+ $this->assertTrue($agg->getParam('explain'));
+ $this->assertInstanceOf('Elastica\Aggregation\TopHits', $returnValue);
+
+ $agg->setExplain(false);
+ $this->assertFalse($agg->getParam('explain'));
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetHighlight()
+ {
+ $highlight = array(
+ 'fields' => array(
+ 'title',
+ ),
+ );
+ $agg = new TopHits('agg_name');
+ $returnValue = $agg->setHighlight($highlight);
+ $this->assertEquals($highlight, $agg->getParam('highlight'));
+ $this->assertInstanceOf('Elastica\Aggregation\TopHits', $returnValue);
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetFieldDataFields()
+ {
+ $fields = array('title', 'tags');
+ $agg = new TopHits('agg_name');
+ $returnValue = $agg->setFieldDataFields($fields);
+ $this->assertEquals($fields, $agg->getParam('fielddata_fields'));
+ $this->assertInstanceOf('Elastica\Aggregation\TopHits', $returnValue);
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetScriptFields()
+ {
+ $script = new Script('1 + 2');
+ $scriptFields = new ScriptFields(array('three' => $script));
+
+ $agg = new TopHits('agg_name');
+ $returnValue = $agg->setScriptFields($scriptFields);
+ $this->assertEquals($scriptFields->toArray(), $agg->getParam('script_fields'));
+ $this->assertInstanceOf('Elastica\Aggregation\TopHits', $returnValue);
+ }
+
+ /**
+ * @group unit
+ */
+ public function testAddScriptField()
+ {
+ $script = new Script('2+3');
+ $agg = new TopHits('agg_name');
+ $returnValue = $agg->addScriptField('five', $script);
+ $this->assertEquals(array('five' => $script->toArray()), $agg->getParam('script_fields'));
+ $this->assertInstanceOf('Elastica\Aggregation\TopHits', $returnValue);
+ }
+
+ protected function getOuterAggregationResult($innerAggr)
+ {
+ $outerAggr = new Terms('top_tags');
+ $outerAggr->setField('tags');
+ $outerAggr->setMinimumDocumentCount(2);
+ $outerAggr->addAggregation($innerAggr);
+
+ $query = new Query(new MatchAll());
+ $query->addAggregation($outerAggr);
+
+ return $this->_getIndexForTest()->search($query)->getAggregation('top_tags');
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAggregateUpdatedRecently()
+ {
+ $aggr = new TopHits('top_tag_hits');
+ $aggr->setSize(1);
+ $aggr->setSort(array('last_activity_date' => array('order' => 'desc')));
+
+ $resultDocs = array();
+ $outerAggrResult = $this->getOuterAggregationResult($aggr);
+ foreach ($outerAggrResult['buckets'] as $bucket) {
+ foreach ($bucket['top_tag_hits']['hits']['hits'] as $doc) {
+ $resultDocs[] = $doc['_id'];
+ }
+ }
+ $this->assertEquals(array(1, 3), $resultDocs);
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAggregateUpdatedFarAgo()
+ {
+ $aggr = new TopHits('top_tag_hits');
+ $aggr->setSize(1);
+ $aggr->setSort(array('last_activity_date' => array('order' => 'asc')));
+
+ $resultDocs = array();
+ $outerAggrResult = $this->getOuterAggregationResult($aggr);
+ foreach ($outerAggrResult['buckets'] as $bucket) {
+ foreach ($bucket['top_tag_hits']['hits']['hits'] as $doc) {
+ $resultDocs[] = $doc['_id'];
+ }
+ }
+ $this->assertEquals(array(2, 4), $resultDocs);
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAggregateTwoDocumentPerTag()
+ {
+ $aggr = new TopHits('top_tag_hits');
+ $aggr->setSize(2);
+
+ $resultDocs = array();
+ $outerAggrResult = $this->getOuterAggregationResult($aggr);
+ foreach ($outerAggrResult['buckets'] as $bucket) {
+ foreach ($bucket['top_tag_hits']['hits']['hits'] as $doc) {
+ $resultDocs[] = $doc['_id'];
+ }
+ }
+ $this->assertEquals(array(1, 2, 3, 4), $resultDocs);
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAggregateTwoDocumentPerTagWithOffset()
+ {
+ $aggr = new TopHits('top_tag_hits');
+ $aggr->setSize(2);
+ $aggr->setFrom(1);
+ $aggr->setSort(array('last_activity_date' => array('order' => 'desc')));
+
+ $resultDocs = array();
+ $outerAggrResult = $this->getOuterAggregationResult($aggr);
+ foreach ($outerAggrResult['buckets'] as $bucket) {
+ foreach ($bucket['top_tag_hits']['hits']['hits'] as $doc) {
+ $resultDocs[] = $doc['_id'];
+ }
+ }
+ $this->assertEquals(array(2, 4), $resultDocs);
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAggregateWithLimitedSource()
+ {
+ $aggr = new TopHits('top_tag_hits');
+ $aggr->setSource(array('title'));
+
+ $resultDocs = array();
+ $outerAggrResult = $this->getOuterAggregationResult($aggr);
+ foreach ($outerAggrResult['buckets'] as $bucket) {
+ foreach ($bucket['top_tag_hits']['hits']['hits'] as $doc) {
+ $this->assertArrayHasKey('title', $doc['_source']);
+ $this->assertArrayNotHasKey('tags', $doc['_source']);
+ $this->assertArrayNotHasKey('last_activity_date', $doc['_source']);
+ }
+ }
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAggregateWithVersion()
+ {
+ $aggr = new TopHits('top_tag_hits');
+ $aggr->setVersion(true);
+
+ $resultDocs = array();
+ $outerAggrResult = $this->getOuterAggregationResult($aggr);
+ foreach ($outerAggrResult['buckets'] as $bucket) {
+ foreach ($bucket['top_tag_hits']['hits']['hits'] as $doc) {
+ $this->assertArrayHasKey('_version', $doc);
+ }
+ }
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAggregateWithExplain()
+ {
+ $aggr = new TopHits('top_tag_hits');
+ $aggr->setExplain(true);
+
+ $resultDocs = array();
+ $outerAggrResult = $this->getOuterAggregationResult($aggr);
+ foreach ($outerAggrResult['buckets'] as $bucket) {
+ foreach ($bucket['top_tag_hits']['hits']['hits'] as $doc) {
+ $this->assertArrayHasKey('_explanation', $doc);
+ }
+ }
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAggregateWithScriptFields()
+ {
+ $aggr = new TopHits('top_tag_hits');
+ $aggr->setSize(1);
+ $aggr->setScriptFields(array('three' => new Script('1 + 2')));
+ $aggr->addScriptField('five', new Script('3 + 2'));
+
+ $resultDocs = array();
+ $outerAggrResult = $this->getOuterAggregationResult($aggr);
+ foreach ($outerAggrResult['buckets'] as $bucket) {
+ foreach ($bucket['top_tag_hits']['hits']['hits'] as $doc) {
+ $this->assertEquals(3, $doc['fields']['three'][0]);
+ $this->assertEquals(5, $doc['fields']['five'][0]);
+ }
+ }
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAggregateWithHighlight()
+ {
+ $queryString = new SimpleQueryString('linux', array('title'));
+
+ $aggr = new TopHits('top_tag_hits');
+ $aggr->setHighlight(array('fields' => array('title' => new \stdClass())));
+
+ $query = new Query($queryString);
+ $query->addAggregation($aggr);
+
+ $resultSet = $this->_getIndexForTest()->search($query);
+ $aggrResult = $resultSet->getAggregation('top_tag_hits');
+
+ foreach ($aggrResult['hits']['hits'] as $doc) {
+ $this->assertArrayHasKey('highlight', $doc);
+ $this->assertRegExp('#<em>linux</em>#', $doc['highlight']['title'][0]);
+ }
+ }
+
+ /**
+ * @group functional
+ */
+ public function testAggregateWithFieldData()
+ {
+ $aggr = new TopHits('top_tag_hits');
+ $aggr->setFieldDataFields(array('title'));
+
+ $query = new Query(new MatchAll());
+ $query->addAggregation($aggr);
+
+ $resultSet = $this->_getIndexForTest()->search($query);
+ $aggrResult = $resultSet->getAggregation('top_tag_hits');
+
+ foreach ($aggrResult['hits']['hits'] as $doc) {
+ $this->assertArrayHasKey('fields', $doc);
+ $this->assertArrayHasKey('title', $doc['fields']);
+ $this->assertArrayNotHasKey('tags', $doc['fields']);
+ $this->assertArrayNotHasKey('last_activity_date', $doc['fields']);
+ }
+ }
+}
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ValueCountTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ValueCountTest.php
index 5eba9ea4..21b63cbe 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ValueCountTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ValueCountTest.php
@@ -1,38 +1,40 @@
<?php
-
namespace Elastica\Test\Aggregation;
-
use Elastica\Aggregation\ValueCount;
use Elastica\Document;
use Elastica\Query;
class ValueCountTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- 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();
+ $index = $this->_createIndex();
+
+ $index->getType('test')->addDocuments(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)),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group functional
+ */
public function testValueCountAggregation()
{
- $agg = new ValueCount("count", "price");
+ $agg = new ValueCount('count', 'price');
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("count");
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('count');
$this->assertEquals(5, $results['value']);
}
}
- \ No newline at end of file