diff options
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Facet')
7 files changed, 172 insertions, 100 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/DateHistogramTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/DateHistogramTest.php index 46dcdbf9..96d30aa2 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/DateHistogramTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/DateHistogramTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Facet; use Elastica\Document; @@ -11,6 +10,9 @@ use Elastica\Type\Mapping; class DateHistogramTest extends BaseTest { + /** + * @group unit + */ public function testClassHierarchy() { $facet = new DateHistogram('dateHist1'); @@ -19,7 +21,51 @@ class DateHistogramTest extends BaseTest unset($facet); } - public function testTest() + /** + * @group functional + */ + public function testQuery() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $mapping = new Mapping($type, array( + 'name' => array('type' => 'string', 'store' => 'no'), + 'dtmPosted' => array('type' => 'date', 'store' => 'no', 'format' => 'yyyy-MM-dd HH:mm:ss'), + )); + $type->setMapping($mapping); + + $doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => '2011-06-23 21:53:00')); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => '2011-06-23 09:53:00')); + $type->addDocument($doc); + $doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => '2011-07-08 08:53:00')); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => '2011-07-08 01:53:00')); + $type->addDocument($doc); + + $facet = new DateHistogram('dateHist1'); + $facet->setInterval('day'); + $facet->setField('dtmPosted'); + + $query = new Query(); + $query->addFacet($facet); + $query->setQuery(new MatchAll()); + $index->refresh(); + + $response = $type->search($query); + $facets = $response->getFacets(); + + $this->assertEquals(4, $response->getTotalHits()); + $this->assertEquals(2, count($facets['dateHist1']['entries'])); + } + + /** + * @group functional + */ + public function testFactor() { $client = $this->_getClient(); $index = $client->getIndex('test'); @@ -28,22 +74,23 @@ class DateHistogramTest extends BaseTest $mapping = new Mapping($type, array( 'name' => array('type' => 'string', 'store' => 'no'), - 'dtmPosted' => array('type' => 'date', 'store' => 'no', 'format' => 'yyyy-MM-dd HH:mm:ss') + 'dtmPosted' => array('type' => 'long', 'store' => 'no'), )); $type->setMapping($mapping); - $doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => "2011-06-23 21:53:00")); + $doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => 1308865980)); $type->addDocument($doc); - $doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => "2011-06-23 09:53:00")); + $doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => 1308822780)); $type->addDocument($doc); - $doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => "2011-07-08 08:53:00")); + $doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => 1310115180)); $type->addDocument($doc); - $doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => "2011-07-08 01:53:00")); + $doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => 1310089980)); $type->addDocument($doc); $facet = new DateHistogram('dateHist1'); - $facet->setInterval("day"); - $facet->setField("dtmPosted"); + $facet->setInterval('day'); + $facet->setField('dtmPosted'); + $facet->setFactor(1000); $query = new Query(); $query->addFacet($facet); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/FilterTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/FilterTest.php index ca6f5ba3..622923fe 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/FilterTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/FilterTest.php @@ -1,15 +1,17 @@ <?php - namespace Elastica\Test\Facet; use Elastica\Document; -use Elastica\Filter\Term; use Elastica\Facet\Filter; +use Elastica\Filter\Term; use Elastica\Query; use Elastica\Test\Base as BaseTest; class FilterTest extends BaseTest { + /** + * @group functional + */ public function testFilter() { $client = $this->_getClient(); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/GeoClusterTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/GeoClusterTest.php index d06b58f9..f771ac32 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/GeoClusterTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/GeoClusterTest.php @@ -1,42 +1,50 @@ <?php - namespace Elastica\Test\Facet; +use Elastica\Document; +use Elastica\Facet\GeoCluster; +use Elastica\Query; use Elastica\Test\Base as BaseTest; - -class GeoClusterTest extends BaseTest{ - public function testQuery() { +use Elastica\Type\Mapping; + +class GeoClusterTest extends BaseTest +{ + /** + * @group functional + */ + public function testQuery() + { $client = $this->_getClient(); $nodes = $client->getCluster()->getNodes(); - if(!$nodes[0]->getInfo()->hasPlugin('geocluster-facet')){ + if (!$nodes[0]->getInfo()->hasPlugin('geocluster-facet')) { $this->markTestSkipped('geocluster-facet plugin not installed'); } - $index = $this->_createIndex('geocluster_test'); + $index = $this->_createIndex(); $type = $index->getType('testQuery'); $geoField = 'location'; - $type->setMapping(new \Elastica\Type\Mapping($type, array( - $geoField => array( 'type' => 'geo_point', 'lat_lon' => true ) + $type->setMapping(new Mapping($type, array( + $geoField => array('type' => 'geo_point', 'lat_lon' => true), ))); - $doc = new \Elastica\Document(1, array('name' => 'item1', 'location' => array(20,20))); + $doc = new Document(1, array('name' => 'item1', 'location' => array(20, 20))); $type->addDocument($doc); - $doc = new \Elastica\Document(2, array('name' => 'item2', 'location' => array(20,20))); + $doc = new Document(2, array('name' => 'item2', 'location' => array(20, 20))); $type->addDocument($doc); - $doc = new \Elastica\Document(3, array('name' => 'item3', 'location' => array(20,20))); + $doc = new Document(3, array('name' => 'item3', 'location' => array(20, 20))); $type->addDocument($doc); $index->refresh(); - $facet = new \Elastica\Facet\GeoCluster('clusters'); + $facet = new GeoCluster('clusters'); $facet ->setField($geoField) ->setFactor(1) ->setShowIds(false); - $query = new \Elastica\Query(); + $query = new Query(); $query->setFacets(array($facet)); $response = $type->search($query); @@ -46,4 +54,4 @@ class GeoClusterTest extends BaseTest{ $index->delete(); } -}
\ No newline at end of file +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/QueryTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/QueryTest.php index ef5d7ccd..8e0231aa 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/QueryTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/QueryTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Facet; use Elastica\Document; @@ -10,6 +9,9 @@ use Elastica\Test\Base as BaseTest; class QueryTest extends BaseTest { + /** + * @group functional + */ public function testFilter() { $client = $this->_getClient(); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/StatisticalTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/StatisticalTest.php index 0b528a79..dc374289 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/StatisticalTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/StatisticalTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Facet; use Elastica\Document; @@ -8,8 +7,14 @@ use Elastica\Query; use Elastica\Query\MatchAll; use Elastica\Test\Base as BaseTest; +/** + * @todo Add test for Statistical with setScript + */ class StatisticalTest extends BaseTest { + /** + * @group functional + */ public function testStatisticalWithSetField() { $client = $this->_getClient(); @@ -41,6 +46,9 @@ class StatisticalTest extends BaseTest $this->assertEquals(45, $facets['stats']['max']); } + /** + * @group functional + */ public function testStatisticalWithSetFields() { $client = $this->_getClient(); @@ -56,7 +64,7 @@ class StatisticalTest extends BaseTest $type->addDocument($doc); $facet = new Statistical('stats'); - $facet->setFields(array('price','price2')); + $facet->setFields(array('price', 'price2')); $query = new Query(); $query->addFacet($facet); @@ -71,12 +79,4 @@ class StatisticalTest extends BaseTest $this->assertEquals(10, $facets['stats']['min']); $this->assertEquals(90, $facets['stats']['max']); } - - /** - * @todo - */ - public function testStatisticalWithSetScript() - { - $this->markTestIncomplete('Test for setting the script value'); - } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsStatsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsStatsTest.php index bea9b78d..e3377930 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsStatsTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsStatsTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Facet; use Elastica\Document; @@ -10,96 +9,105 @@ use Elastica\Test\Base as BaseTest; class TermsStatsTest extends BaseTest { + /** + * @group functional + */ public function testOrder() { $client = $this->_getClient(); - $index = $client->getIndex( 'test' ); - $index->create( array( ), true ); - $type = $index->getType( 'helloworld' ); - - $doc = new Document( 1, array( 'name' => 'tom', 'paid' => 7 ) ); - $type->addDocument( $doc ); - $doc = new Document( 2, array( 'name' => 'tom', 'paid' => 2 ) ); - $type->addDocument( $doc ); - $doc = new Document( 3, array( 'name' => 'tom', 'paid' => 5 ) ); - $type->addDocument( $doc ); - $doc = new Document( 4, array( 'name' => 'mike', 'paid' => 13 ) ); - $type->addDocument( $doc ); - $doc = new Document( 5, array( 'name' => 'mike', 'paid' => 1 ) ); - $type->addDocument( $doc ); - $doc = new Document( 6, array( 'name' => 'mike', 'paid' => 15 ) ); - $type->addDocument( $doc ); - - $facet = new TermsStats( 'test' ); - $facet->setKeyField( 'name' ); - $facet->setValueField( 'paid' ); - $facet->setOrder( 'reverse_total' ); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $doc = new Document(1, array('name' => 'tom', 'paid' => 7)); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'tom', 'paid' => 2)); + $type->addDocument($doc); + $doc = new Document(3, array('name' => 'tom', 'paid' => 5)); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'mike', 'paid' => 13)); + $type->addDocument($doc); + $doc = new Document(5, array('name' => 'mike', 'paid' => 1)); + $type->addDocument($doc); + $doc = new Document(6, array('name' => 'mike', 'paid' => 15)); + $type->addDocument($doc); + + $facet = new TermsStats('test'); + $facet->setKeyField('name'); + $facet->setValueField('paid'); + $facet->setOrder('reverse_total'); $query = new Query(); - $query->addFacet( $facet ); - $query->setQuery( new MatchAll() ); + $query->addFacet($facet); + $query->setQuery(new MatchAll()); $index->refresh(); - $response = $type->search( $query ); - $facets = $response->getFacets(); + $response = $type->search($query); + $facets = $response->getFacets(); - $this->assertEquals(14, $facets[ 'test' ][ 'terms' ][0]['total'] ); - $this->assertEquals(29, $facets[ 'test' ][ 'terms' ][1]['total'] ); + $this->assertEquals(14, $facets[ 'test' ][ 'terms' ][0]['total']); + $this->assertEquals(29, $facets[ 'test' ][ 'terms' ][1]['total']); } + /** + * @group functional + */ public function testQuery() { $client = $this->_getClient(); - $index = $client->getIndex( 'test' ); - $index->create( array( ), true ); - $type = $index->getType( 'helloworld' ); - - $doc = new Document( 1, array( 'name' => 'tom', 'paid' => 7 ) ); - $type->addDocument( $doc ); - $doc = new Document( 2, array( 'name' => 'tom', 'paid' => 2 ) ); - $type->addDocument( $doc ); - $doc = new Document( 3, array( 'name' => 'tom', 'paid' => 5 ) ); - $type->addDocument( $doc ); - $doc = new Document( 4, array( 'name' => 'mike', 'paid' => 13 ) ); - $type->addDocument( $doc ); - $doc = new Document( 5, array( 'name' => 'mike', 'paid' => 1 ) ); - $type->addDocument( $doc ); - $doc = new Document( 6, array( 'name' => 'mike', 'paid' => 15 ) ); - $type->addDocument( $doc ); - - $facet = new TermsStats( 'test' ); - $facet->setKeyField( 'name' ); - $facet->setValueField( 'paid' ); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $doc = new Document(1, array('name' => 'tom', 'paid' => 7)); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'tom', 'paid' => 2)); + $type->addDocument($doc); + $doc = new Document(3, array('name' => 'tom', 'paid' => 5)); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'mike', 'paid' => 13)); + $type->addDocument($doc); + $doc = new Document(5, array('name' => 'mike', 'paid' => 1)); + $type->addDocument($doc); + $doc = new Document(6, array('name' => 'mike', 'paid' => 15)); + $type->addDocument($doc); + + $facet = new TermsStats('test'); + $facet->setKeyField('name'); + $facet->setValueField('paid'); $query = new Query(); - $query->addFacet( $facet ); - $query->setQuery( new MatchAll() ); + $query->addFacet($facet); + $query->setQuery(new MatchAll()); $index->refresh(); - $response = $type->search( $query ); - $facets = $response->getFacets(); + $response = $type->search($query); + $facets = $response->getFacets(); - $this->assertEquals( 2, count( $facets[ 'test' ][ 'terms' ] ) ); + $this->assertEquals(2, count($facets[ 'test' ][ 'terms' ])); foreach ($facets[ 'test' ][ 'terms' ] as $facet) { if ($facet[ 'term' ] === 'tom') { - $this->assertEquals( 14, $facet[ 'total' ] ); + $this->assertEquals(14, $facet[ 'total' ]); } if ($facet[ 'term' ] === 'mike') { - $this->assertEquals( 29, $facet[ 'total' ] ); + $this->assertEquals(29, $facet[ 'total' ]); } } } - public function testSetSize() - { - $facet = new TermsStats( 'test' ); - $facet->setSize(100); + /** + * @group unit + */ + public function testSetSize() + { + $facet = new TermsStats('test'); + $facet->setSize(100); - $data = $facet->toArray(); + $data = $facet->toArray(); - $this->assertArrayHasKey('size', $data['terms_stats']); - $this->assertEquals(100, $data['terms_stats']['size']); - } + $this->assertArrayHasKey('size', $data['terms_stats']); + $this->assertEquals(100, $data['terms_stats']['size']); + } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsTest.php index e8521c5c..f4c95796 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Facet; use Elastica\Document; @@ -10,6 +9,9 @@ use Elastica\Test\Base as BaseTest; class TermsTest extends BaseTest { + /** + * @group functional + */ public function testQuery() { $client = $this->_getClient(); @@ -39,6 +41,9 @@ class TermsTest extends BaseTest $this->assertEquals(3, count($facets['test']['terms'])); } + /** + * @group functional + */ public function testFacetScript() { $client = $this->_getClient(); |