diff options
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Query')
32 files changed, 1619 insertions, 627 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/BoolTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/BoolQueryTest.php index d3bd90cd..211d0c23 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/BoolTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/BoolQueryTest.php @@ -1,20 +1,22 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; use Elastica\Index; -use Elastica\Query\Bool; +use Elastica\Query\BoolQuery; use Elastica\Query\Ids; use Elastica\Query\Term; use Elastica\Test\Base as BaseTest; use Elastica\Type; -class BoolTest extends BaseTest +class BoolQueryTest extends BaseTest { + /** + * @group unit + */ public function testToArray() { - $query = new Bool(); + $query = new BoolQuery(); $idsQuery1 = new Ids(); $idsQuery1->setIds(1); @@ -41,20 +43,22 @@ class BoolTest extends BaseTest 'minimum_number_should_match' => $minMatch, 'must_not' => array($idsQuery2->toArray()), 'boost' => $boost, - ) + ), ); $this->assertEquals($expectedArray, $query->toArray()); } /** - * Test to resolve the following issue + * Test to resolve the following issue. + * + * @link https://groups.google.com/forum/?fromgroups#!topic/elastica-php-client/zK_W_hClfvU * - * https://groups.google.com/forum/?fromgroups#!topic/elastica-php-client/zK_W_hClfvU + * @group unit */ public function testToArrayStructure() { - $boolQuery = new Bool(); + $boolQuery = new BoolQuery(); $term1 = new Term(); $term1->setParam('interests', 84); @@ -68,6 +72,9 @@ class BoolTest extends BaseTest $this->assertEquals($jsonString, json_encode($boolQuery->toArray())); } + /** + * @group functional + */ public function testSearch() { $client = $this->_getClient(); @@ -86,7 +93,7 @@ class BoolTest extends BaseTest // Refresh index $index->refresh(); - $boolQuery = new Bool(); + $boolQuery = new BoolQuery(); $termQuery1 = new Term(array('test' => '2')); $boolQuery->addMust($termQuery1); $resultSet = $type->search($boolQuery); @@ -111,4 +118,54 @@ class BoolTest extends BaseTest $this->assertEquals(0, $resultSet->count()); } + + /** + * @group functional + */ + public function testEmptyBoolQuery() + { + $index = $this->_createIndex(); + $type = new Type($index, 'test'); + + $docNumber = 3; + for ($i = 0; $i < $docNumber; $i++) { + $doc = new Document($i, array('email' => 'test@test.com')); + $type->addDocument($doc); + } + + $index->refresh(); + + $boolQuery = new BoolQuery(); + + $resultSet = $type->search($boolQuery); + + $this->assertEquals($resultSet->count(), $docNumber); + } + + /** + * @group functional + */ + public function testOldObject() + { + if (version_compare(phpversion(), 7, '>=')) { + self::markTestSkipped('These objects are not supported in PHP 7'); + } + + $index = $this->_createIndex(); + $type = new Type($index, 'test'); + + $docNumber = 3; + for ($i = 0; $i < $docNumber; $i++) { + $doc = new Document($i, array('email' => 'test@test.com')); + $type->addDocument($doc); + } + + $index->refresh(); + + $boolQuery = new \Elastica\Query\Bool(); + + $resultSet = $type->search($boolQuery); + + $this->assertEquals($resultSet->count(), $docNumber); + } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/BoostingTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/BoostingTest.php index f5af8740..8133fd37 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/BoostingTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/BoostingTest.php @@ -1,67 +1,54 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; use Elastica\Query\Boosting; +use Elastica\Query\Term; use Elastica\Test\Base as BaseTest; class BoostingTest extends BaseTest { /** - * @var \Elastica\Index - */ - protected $index; - - /** - * @var \Elastica\Type - */ - protected $type; - - /* * @var array */ - protected $sampleData; - - protected function setUp() + protected $sampleData = array( + array('name' => 'Vital Lama', 'price' => 5.2), + array('name' => 'Vital Match', 'price' => 2.1), + array('name' => 'Mercury Vital', 'price' => 7.5), + array('name' => 'Fist Mercury', 'price' => 3.8), + array('name' => 'Lama Vital 2nd', 'price' => 3.2), + ); + + protected function _getTestIndex() { - parent::setUp(); - $this->index = $this->_createIndex('test_boostingquery'); - $this->type = $this->index->getType('test'); - $this->type->setMapping(array( + $index = $this->_createIndex(); + $type = $index->getType('test'); + $type->setMapping(array( 'name' => array('type' => 'string', 'index' => 'analyzed'), - 'price' => array('type' => 'float') + 'price' => array('type' => 'float'), )); - - $this->sampleData = array( - array("name" => "Vital Lama", "price" => 5.2), - array("name" => "Vital Match", "price" => 2.1), - array("name" => "Mercury Vital", "price" => 7.5), - array("name" => "Fist Mercury", "price" => 3.8), - array("name" => "Lama Vital 2nd", "price" => 3.2) - ); - - foreach($this->sampleData as $key => $value) { - $this->type->addDocument(new Document($key, $value)); + $docs = array(); + foreach ($this->sampleData as $key => $value) { + $docs[] = new Document($key, $value); } + $type->addDocuments($docs); - $this->index->refresh(); - } + $index->refresh(); - protected function tearDown() - { - $this->index->delete(); - parent::tearDown(); + return $index; } + /** + * @group unit + */ public function testToArray() { - $keyword = "vital"; - $negativeKeyword = "Mercury"; + $keyword = 'vital'; + $negativeKeyword = 'Mercury'; $query = new Boosting(); - $positiveQuery = new \Elastica\Query\Term(array('name' => $keyword)); - $negativeQuery = new \Elastica\Query\Term(array('name' => $negativeKeyword)); + $positiveQuery = new Term(array('name' => $keyword)); + $negativeQuery = new Term(array('name' => $negativeKeyword)); $query->setPositiveQuery($positiveQuery); $query->setNegativeQuery($negativeQuery); $query->setNegativeBoost(0.3); @@ -70,25 +57,28 @@ class BoostingTest extends BaseTest 'boosting' => array( 'positive' => $positiveQuery->toArray(), 'negative' => $negativeQuery->toArray(), - 'negative_boost' => 0.3 - ) + 'negative_boost' => 0.3, + ), ); $this->assertEquals($expected, $query->toArray()); } + /** + * @group functional + */ public function testNegativeBoost() { - $keyword = "vital"; - $negativeKeyword = "mercury"; + $keyword = 'vital'; + $negativeKeyword = 'mercury'; $query = new Boosting(); - $positiveQuery = new \Elastica\Query\Term(array('name' => $keyword)); - $negativeQuery = new \Elastica\Query\Term(array('name' => $negativeKeyword)); + $positiveQuery = new Term(array('name' => $keyword)); + $negativeQuery = new Term(array('name' => $negativeKeyword)); $query->setPositiveQuery($positiveQuery); $query->setNegativeQuery($negativeQuery); $query->setNegativeBoost(0.2); - $response = $this->type->search($query); + $response = $this->_getTestIndex()->search($query); $results = $response->getResults(); $this->assertEquals($response->getTotalHits(), 4); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/BuilderTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/BuilderTest.php index 5875c4ba..a96e8b3a 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/BuilderTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/BuilderTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Query\Builder; @@ -8,21 +7,7 @@ use Elastica\Test\Base as BaseTest; class BuilderTest extends BaseTest { /** - * @var \Elastica\Query\Builder - */ - private $builder; - - public function setUp() - { - $this->builder = new Builder(); - } - - public function tearDown() - { - $this->builder = null; - } - - /** + * @group unit * @covers \Elastica\Query\Builder::factory * @covers \Elastica\Query\Builder::__construct */ @@ -66,11 +51,12 @@ class BuilderTest extends BaseTest array('size', 7, '{"size":"7"}'), array('tieBreakerMultiplier', 7, '{"tie_breaker_multiplier":"7"}'), array('matchAll', 1.1, '{"match_all":{"boost":"1.1"}}'), - array('fields', array("age", "sex", "location"), '{"fields":["age","sex","location"]}'), + array('fields', array('age', 'sex', 'location'), '{"fields":["age","sex","location"]}'), ); } /** + * @group unit * @dataProvider getQueryData * @covers \Elastica\Query\Builder::__toString * @covers \Elastica\Query\Builder::allowLeadingWildcard @@ -99,8 +85,9 @@ class BuilderTest extends BaseTest */ public function testAllowLeadingWildcard($method, $argument, $result) { - $this->assertSame($this->builder, $this->builder->$method($argument)); - $this->assertSame($result, (string) $this->builder); + $builder = new Builder(); + $this->assertSame($builder, $builder->$method($argument)); + $this->assertSame($result, (string) $builder); } public function getQueryTypes() @@ -127,11 +114,10 @@ class BuilderTest extends BaseTest } /** + * @group unit * @dataProvider getQueryTypes - * * @covers \Elastica\Query\Builder::fieldClose * @covers \Elastica\Query\Builder::close - * * @covers \Elastica\Query\Builder::bool * @covers \Elastica\Query\Builder::boolClose * @covers \Elastica\Query\Builder::constantScore @@ -169,12 +155,14 @@ class BuilderTest extends BaseTest */ public function testQueryTypes($method, $queryType) { - $this->assertSame($this->builder, $this->builder->$method()); // open - $this->assertSame($this->builder, $this->builder->{$method."Close"}()); // close - $this->assertSame('{"' . $queryType . '":{}}', (string) $this->builder); + $builder = new Builder(); + $this->assertSame($builder, $builder->$method()); // open + $this->assertSame($builder, $builder->{$method.'Close'}()); // close + $this->assertSame('{"'.$queryType.'":{}}', (string) $builder); } /** + * @group unit * @covers \Elastica\Query\Builder::fieldOpen * @covers \Elastica\Query\Builder::fieldClose * @covers \Elastica\Query\Builder::open @@ -182,44 +170,51 @@ class BuilderTest extends BaseTest */ public function testFieldOpenAndClose() { - $this->assertSame($this->builder, $this->builder->fieldOpen('someField')); - $this->assertSame($this->builder, $this->builder->fieldClose()); - $this->assertSame('{"someField":{}}', (string) $this->builder); + $builder = new Builder(); + $this->assertSame($builder, $builder->fieldOpen('someField')); + $this->assertSame($builder, $builder->fieldClose()); + $this->assertSame('{"someField":{}}', (string) $builder); } /** + * @group unit * @covers \Elastica\Query\Builder::sortField */ public function testSortField() { - $this->assertSame($this->builder, $this->builder->sortField('name', true)); - $this->assertSame('{"sort":{"name":{"reverse":"true"}}}', (string) $this->builder); + $builder = new Builder(); + $this->assertSame($builder, $builder->sortField('name', true)); + $this->assertSame('{"sort":{"name":{"reverse":"true"}}}', (string) $builder); } /** + * @group unit * @covers \Elastica\Query\Builder::sortFields */ public function testSortFields() { - $this->assertSame($this->builder, $this->builder->sortFields(array('field1' => 'asc', 'field2' => 'desc', 'field3' => 'asc'))); - $this->assertSame('{"sort":[{"field1":"asc"},{"field2":"desc"},{"field3":"asc"}]}', (string) $this->builder); + $builder = new Builder(); + $this->assertSame($builder, $builder->sortFields(array('field1' => 'asc', 'field2' => 'desc', 'field3' => 'asc'))); + $this->assertSame('{"sort":[{"field1":"asc"},{"field2":"desc"},{"field3":"asc"}]}', (string) $builder); } /** + * @group unit * @covers \Elastica\Query\Builder::queries */ public function testQueries() { $queries = array(); - $b1 = clone $this->builder; - $b2 = clone $this->builder; + $builder = new Builder(); + $b1 = clone $builder; + $b2 = clone $builder; $queries[] = $b1->term()->field('age', 34)->termClose(); $queries[] = $b2->term()->field('name', 'christer')->termClose(); - $this->assertSame($this->builder, $this->builder->queries($queries)); - $this->assertSame('{"queries":[{"term":{"age":"34"}},{"term":{"name":"christer"}}]}', (string) $this->builder); + $this->assertSame($builder, $builder->queries($queries)); + $this->assertSame('{"queries":[{"term":{"age":"34"}},{"term":{"name":"christer"}}]}', (string) $builder); } public function getFieldData() @@ -234,37 +229,45 @@ class BuilderTest extends BaseTest } /** + * @group unit * @dataProvider getFieldData * @covers \Elastica\Query\Builder::field */ public function testField($name, $value, $result) { - $this->assertSame($this->builder, $this->builder->field($name, $value)); - $this->assertSame($result, (string) $this->builder); + $builder = new Builder(); + $this->assertSame($builder, $builder->field($name, $value)); + $this->assertSame($result, (string) $builder); } /** + * @group unit * @expectedException \Elastica\Exception\InvalidException + * @expectedExceptionMessage The produced query is not a valid json string : "{{}" * @covers \Elastica\Query\Builder::toArray */ public function testToArrayWithInvalidData() { - $this->builder->open('foo'); - $this->builder->toArray(); + $builder = new Builder(); + $builder->open('foo'); + $builder->toArray(); } /** + * @group unit * @covers \Elastica\Query\Builder::toArray */ public function testToArray() { - $this->builder->query()->term()->field('category.id', array(1, 2, 3))->termClose()->queryClose(); - $this->assertEquals(array( + $builder = new Builder(); + $builder->query()->term()->field('category.id', array(1, 2, 3))->termClose()->queryClose(); + $expected = array( 'query' => array( 'term' => array( - 'category.id' => array(1, 2, 3) - ) - ) - ), $this->builder->toArray()); + 'category.id' => array(1, 2, 3), + ), + ), + ); + $this->assertEquals($expected, $builder->toArray()); } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/CommonTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/CommonTest.php index a84d6397..016213a8 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/CommonTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/CommonTest.php @@ -1,12 +1,15 @@ <?php - namespace Elastica\Test\Query; +use Elastica\Document; use Elastica\Query\Common; use Elastica\Test\Base as BaseTest; class CommonTest extends BaseTest { + /** + * @group unit + */ public function testToArray() { $query = new Common('body', 'test query', .001); @@ -17,29 +20,32 @@ class CommonTest extends BaseTest 'body' => array( 'query' => 'test query', 'cutoff_frequency' => .001, - 'low_freq_operator' => 'and' - ) - ) + 'low_freq_operator' => 'and', + ), + ), ); $this->assertEquals($expected, $query->toArray()); } + /** + * @group functional + */ public function testQuery() { - $index = $this->_createIndex('common_test'); + $index = $this->_createIndex(); $type = $index->getType('test'); + $docs = array( + new Document(1, array('body' => 'foo baz')), + new Document(2, array('body' => 'foo bar baz')), + new Document(3, array('body' => 'foo bar baz bat')), + ); //add documents to create common terms - $docs = array(); - for ($i = 0; $i < 20; $i++) { - $docs[] = new \Elastica\Document($i, array('body' => 'foo bar')); + for ($i = 4; $i < 24; $i++) { + $docs[] = new Document($i, array('body' => 'foo bar')); } $type->addDocuments($docs); - - $type->addDocument(new \Elastica\Document(20, array('body' => 'foo baz'))); - $type->addDocument(new \Elastica\Document(21, array('body' => 'foo bar baz'))); - $type->addDocument(new \Elastica\Document(22, array('body' => 'foo bar baz bat'))); $index->refresh(); $query = new Common('body', 'foo bar baz bat', .5); @@ -53,7 +59,5 @@ class CommonTest extends BaseTest //only the document containing both low frequency terms should match $this->assertEquals(1, $results->count()); - - $index->delete(); } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php index 27143eb6..a3a213b9 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php @@ -1,15 +1,13 @@ <?php - namespace Elastica\Test\Query; -use Elastica\Filter\Term; +use Elastica\Document; use Elastica\Filter\Ids; +use Elastica\Filter\Term; +use Elastica\Index; use Elastica\Query\ConstantScore; use Elastica\Query\MatchAll; use Elastica\Test\Base as BaseTest; -use Elastica\Index; -use Elastica\Document; -use Elastica\Type; class ConstantScoreTest extends BaseTest { @@ -55,6 +53,7 @@ class ConstantScoreTest extends BaseTest ); } /** + * @group unit * @dataProvider dataProviderSampleQueries */ public function testSimple($filter, $expected) @@ -67,6 +66,9 @@ class ConstantScoreTest extends BaseTest $this->assertEquals($expected, $query->toArray()); } + /** + * @group unit + */ public function testToArray() { $query = new ConstantScore(); @@ -81,13 +83,16 @@ class ConstantScoreTest extends BaseTest $expectedArray = array( 'constant_score' => array( 'filter' => $filter->toArray(), - 'boost' => $boost - ) + 'boost' => $boost, + ), ); $this->assertEquals($expectedArray, $query->toArray()); } + /** + * @group unit + */ public function testConstruct() { $filter = new Ids(); @@ -98,28 +103,25 @@ class ConstantScoreTest extends BaseTest $expectedArray = array( 'constant_score' => array( 'filter' => $filter->toArray(), - ) + ), ); $this->assertEquals($expectedArray, $query->toArray()); - } + /** + * @group functional + */ public function testQuery() { + $index = $this->_createIndex(); - $client = $this->_getClient(); - $index = new Index($client, 'test'); - $index->create(array(), true); - - $type = new Type($index, 'constant_score'); - - $doc = new Document(1, array('id' => 1, 'email' => 'hans@test.com', 'username' => 'hans')); - $type->addDocument($doc); - $doc = new Document(2, array('id' => 2, 'email' => 'emil@test.com', 'username' => 'emil')); - $type->addDocument($doc); - $doc = new Document(3, array('id' => 3, 'email' => 'ruth@test.com', 'username' => 'ruth')); - $type->addDocument($doc); + $type = $index->getType('constant_score'); + $type->addDocuments(array( + new Document(1, array('id' => 1, 'email' => 'hans@test.com', 'username' => 'hans')), + new Document(2, array('id' => 2, 'email' => 'emil@test.com', 'username' => 'emil')), + new Document(3, array('id' => 3, 'email' => 'ruth@test.com', 'username' => 'ruth')), + )); // Refresh index $index->refresh(); @@ -134,8 +136,8 @@ class ConstantScoreTest extends BaseTest $expectedArray = array( 'constant_score' => array( 'query' => $query_match->toArray(), - 'boost' => $boost - ) + 'boost' => $boost, + ), ); $this->assertEquals($expectedArray, $query->toArray()); @@ -145,9 +147,11 @@ class ConstantScoreTest extends BaseTest $this->assertEquals($resultSet->count(), 3); $this->assertEquals($results[1]->getScore(), 1); - } + /** + * @group unit + */ public function testConstructEmpty() { $query = new ConstantScore(); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/DisMaxTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/DisMaxTest.php index 31c8437d..2c128018 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/DisMaxTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/DisMaxTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; @@ -10,6 +9,9 @@ use Elastica\Test\Base as BaseTest; class DisMaxTest extends BaseTest { + /** + * @group unit + */ public function testToArray() { $query = new DisMax(); @@ -39,29 +41,28 @@ class DisMaxTest extends BaseTest 'queries' => array( $idsQuery1->toArray(), $idsQuery2->toArray(), - $idsQuery3->toArray() - ) - ) + $idsQuery3->toArray(), + ), + ), ); $this->assertEquals($expectedArray, $query->toArray()); } + /** + * @group functional + */ public function testQuery() { - $client = $this->_getClient(); - $index = $client->getIndex('test'); - $index->create(array(), true); + $index = $this->_createIndex(); $type = $index->getType('test'); - $doc = new Document(1, array('name' => 'Basel-Stadt')); - $type->addDocument($doc); - $doc = new Document(2, array('name' => 'New York')); - $type->addDocument($doc); - $doc = new Document(3, array('name' => 'Baden')); - $type->addDocument($doc); - $doc = new Document(4, array('name' => 'Baden Baden')); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'Baden')), + new Document(4, array('name' => 'Baden Baden')), + )); $index->refresh(); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/EscapeStringTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/EscapeStringTest.php new file mode 100644 index 00000000..536a7bb3 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/EscapeStringTest.php @@ -0,0 +1,36 @@ +<?php +namespace Elastica\Test\Query; + +use Elastica\Document; +use Elastica\Index; +use Elastica\Query\QueryString; +use Elastica\Test\Base as BaseTest; +use Elastica\Type; +use Elastica\Util; + +class EscapeStringTest extends BaseTest +{ + /** + * @group functional + */ + public function testSearch() + { + $index = $this->_createIndex(); + $index->getSettings()->setNumberOfReplicas(0); + + $type = new Type($index, 'helloworld'); + + $doc = new Document(1, array( + 'email' => 'test@test.com', 'username' => 'test 7/6 123', 'test' => array('2', '3', '5'), ) + ); + $type->addDocument($doc); + + // Refresh index + $index->refresh(); + + $queryString = new QueryString(Util::escapeTerm('test 7/6')); + $resultSet = $type->search($queryString); + + $this->assertEquals(1, $resultSet->count()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FilteredTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FilteredTest.php index c6bd9096..c4bea6f2 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FilteredTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FilteredTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; @@ -10,15 +9,18 @@ use Elastica\Test\Base as BaseTest; class FilteredTest extends BaseTest { + /** + * @group functional + */ public function testFilteredSearch() { $index = $this->_createIndex(); $type = $index->getType('helloworld'); - $doc = new Document(1, array('id' => 1, 'email' => 'test@test.com', 'username' => 'hanswurst', 'test' => array('2', '3', '5'))); - $type->addDocument($doc); - $doc = new Document(2, array('id' => 2, 'email' => 'test@test.com', 'username' => 'peter', 'test' => array('2', '3', '5'))); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1, array('id' => 1, 'email' => 'test@test.com', 'username' => 'hanswurst', 'test' => array('2', '3', '5'))), + new Document(2, array('id' => 2, 'email' => 'test@test.com', 'username' => 'peter', 'test' => array('2', '3', '5'))), + )); $queryString = new QueryString('test*'); @@ -42,6 +44,9 @@ class FilteredTest extends BaseTest $this->assertEquals(0, $resultSet->count()); } + /** + * @group unit + */ public function testFilteredGetter() { $queryString = new QueryString('test*'); @@ -62,6 +67,7 @@ class FilteredTest extends BaseTest } /** + * @group unit * @expectedException \Elastica\Exception\InvalidException */ public function testFilteredWithoutArgumentsShouldRaiseException() @@ -69,27 +75,34 @@ class FilteredTest extends BaseTest $query = new Filtered(); $query->toArray(); } - + + /** + * @group functional + */ public function testFilteredSearchNoQuery() { $index = $this->_createIndex(); $type = $index->getType('helloworld'); - $doc = new Document(1, array('id' => 1, 'email' => 'test@test.com', 'username' => 'hanswurst', 'test' => array('2', '3', '5'))); - $type->addDocument($doc); - $doc = new Document(2, array('id' => 2, 'email' => 'test@test.com', 'username' => 'peter', 'test' => array('2', '3', '5'))); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1, array('id' => 1, 'email' => 'test@test.com', 'username' => 'hanswurst', 'test' => array('2', '3', '5'))), + new Document(2, array('id' => 2, 'email' => 'test@test.com', 'username' => 'peter', 'test' => array('2', '3', '5'))), + )); + + $index->refresh(); $filter = new Term(); $filter->setTerm('username', 'peter'); $query = new Filtered(null, $filter); - $index->refresh(); $resultSet = $type->search($query); $this->assertEquals(1, $resultSet->count()); } - + + /** + * @group functional + */ public function testFilteredSearchNoFilter() { $index = $this->_createIndex(); @@ -108,5 +121,4 @@ class FilteredTest extends BaseTest $resultSet = $type->search($query); $this->assertEquals(1, $resultSet->count()); } - } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FunctionScoreTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FunctionScoreTest.php index 47d9dd2c..25600034 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FunctionScoreTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FunctionScoreTest.php @@ -1,70 +1,56 @@ <?php -/** - * User: Joe Linn - * Date: 9/16/13 - * Time: 5:05 PM - */ - namespace Elastica\Test\Query; use Elastica\Document; use Elastica\Filter\Term; use Elastica\Query\FunctionScore; +use Elastica\Query\MatchAll; use Elastica\Script; use Elastica\Test\Base as BaseTest; class FunctionScoreTest extends BaseTest { - /** - * @var \Elastica\Index - */ - protected $index; - - /** - * @var \Elastica\Type - */ - protected $type; - - protected $locationOrigin = "32.804654, -117.242594"; + protected $locationOrigin = '32.804654, -117.242594'; - protected function setUp() + protected function _getIndexForTest() { - parent::setUp(); - $this->index = $this->_createIndex('test_functionscore'); - $this->type = $this->index->getType('test'); - $this->type->setMapping(array( + $index = $this->_createIndex(); + $type = $index->getType('test'); + + $type->setMapping(array( 'name' => array('type' => 'string', 'index' => 'not_analyzed'), 'location' => array('type' => 'geo_point'), - 'price' => array('type' => 'float') + 'price' => array('type' => 'float'), )); - $this->type->addDocument(new Document(1, array( - 'name' => "Mr. Frostie's", - 'location' => array('lat' => 32.799605, 'lon' => -117.243027), - 'price' => 4.5 - ))); - $this->type->addDocument(new Document(2, array( - 'name' => "Miller's Field", - 'location' => array('lat' => 32.795964, 'lon' => -117.255028), - 'price' => 9.5 - ))); - - $this->index->refresh(); - } + $type->addDocuments(array( + new Document(1, array( + 'name' => "Mr. Frostie's", + 'location' => array('lat' => 32.799605, 'lon' => -117.243027), + 'price' => 4.5, + )), + new Document(2, array( + 'name' => "Miller's Field", + 'location' => array('lat' => 32.795964, 'lon' => -117.255028), + 'price' => 9.5, + )), + )); - protected function tearDown() - { - $this->index->delete(); - parent::tearDown(); + $index->refresh(); + + return $index; } + /** + * @group unit + */ public function testToArray() { $priceOrigin = 0; $locationScale = '2mi'; $priceScale = 9.25; $query = new FunctionScore(); - $childQuery = new \Elastica\Query\MatchAll(); + $childQuery = new MatchAll(); $query->setQuery($childQuery); $query->addDecayFunction(FunctionScore::DECAY_GAUSS, 'location', $this->locationOrigin, $locationScale); $query->addDecayFunction(FunctionScore::DECAY_GAUSS, 'price', $priceOrigin, $priceScale); @@ -76,30 +62,82 @@ class FunctionScoreTest extends BaseTest 'gauss' => array( 'location' => array( 'origin' => $this->locationOrigin, - 'scale' => $locationScale - ) - ) + 'scale' => $locationScale, + ), + ), ), array( 'gauss' => array( 'price' => array( 'origin' => $priceOrigin, - 'scale' => $priceScale - ) - ) - ) - ) - ) + 'scale' => $priceScale, + ), + ), + ), + ), + ), ); $this->assertEquals($expected, $query->toArray()); } + /** + * @group unit + */ + public function testDecayWeight() + { + $priceOrigin = 0; + $locationScale = '2mi'; + $priceScale = 9.25; + $query = new FunctionScore(); + $childQuery = new MatchAll(); + $query->setQuery($childQuery); + $query->addDecayFunction( + FunctionScore::DECAY_GAUSS, + 'location', + $this->locationOrigin, + $locationScale, + null, + null, + .5 + ); + $query->addDecayFunction(FunctionScore::DECAY_GAUSS, 'price', $priceOrigin, $priceScale, null, null, 2); + $expected = array( + 'function_score' => array( + 'query' => $childQuery->toArray(), + 'functions' => array( + array( + 'gauss' => array( + 'location' => array( + 'origin' => $this->locationOrigin, + 'scale' => $locationScale, + ), + ), + 'weight' => .5, + ), + array( + 'gauss' => array( + 'price' => array( + 'origin' => $priceOrigin, + 'scale' => $priceScale, + ), + ), + 'weight' => 2, + ), + ), + ), + ); + $this->assertEquals($expected, $query->toArray()); + } + + /** + * @group functional + */ public function testGauss() { $query = new FunctionScore(); - $query->addDecayFunction(FunctionScore::DECAY_GAUSS, 'location', $this->locationOrigin, "4mi"); + $query->addDecayFunction(FunctionScore::DECAY_GAUSS, 'location', $this->locationOrigin, '4mi'); $query->addDecayFunction(FunctionScore::DECAY_GAUSS, 'price', 0, 10); - $response = $this->type->search($query); + $response = $this->_getIndexForTest()->search($query); $results = $response->getResults(); // the document with the closest location and lowest price should be scored highest @@ -107,7 +145,10 @@ class FunctionScoreTest extends BaseTest $this->assertEquals("Mr. Frostie's", $result0['name']); } - public function testBoostFactor() + /** + * @group functional + */ + public function testWeight() { $filter = new Term(array('price' => 4.5)); $query = new FunctionScore(); @@ -116,20 +157,20 @@ class FunctionScoreTest extends BaseTest 'function_score' => array( 'functions' => array( array( - 'boost_factor' => 5.0, + 'weight' => 5.0, 'filter' => array( 'term' => array( - 'price' => 4.5 - ) - ) - ) - ) - ) + 'price' => 4.5, + ), + ), + ), + ), + ), ); $this->assertEquals($expected, $query->toArray()); - $response = $this->type->search($query); + $response = $this->_getIndexForTest()->search($query); $results = $response->getResults(); // the document with price = 4.5 should be scored highest @@ -137,6 +178,9 @@ class FunctionScoreTest extends BaseTest $this->assertEquals("Mr. Frostie's", $result0['name']); } + /** + * @group functional + */ public function testRandomScore() { $filter = new Term(array('price' => 4.5)); @@ -147,39 +191,74 @@ class FunctionScoreTest extends BaseTest 'functions' => array( array( 'random_score' => array( - 'seed' => 2 + 'seed' => 2, ), 'filter' => array( 'term' => array( - 'price' => 4.5 - ) - ) - ) - ) - ) + 'price' => 4.5, + ), + ), + ), + ), + ), ); $this->assertEquals($expected, $query->toArray()); - $response = $this->type->search($query); + $response = $this->_getIndexForTest()->search($query); $results = $response->getResults(); // the document with the random score should have a score > 1, means it is the first result - $result0 = $results[1]->getData(); - + $result0 = $results[0]->getData(); + $this->assertEquals("Miller's Field", $result0['name']); } + /** + * @group unit + */ + public function testRandomScoreWeight() + { + $filter = new Term(array('price' => 4.5)); + $query = new FunctionScore(); + $query->addRandomScoreFunction(2, $filter, 2); + $expected = array( + 'function_score' => array( + 'functions' => array( + array( + 'random_score' => array( + 'seed' => 2, + ), + 'filter' => array( + 'term' => array( + 'price' => 4.5, + ), + ), + 'weight' => 2, + ), + ), + ), + ); + + $this->assertEquals($expected, $query->toArray()); + } + + /** + * @group functional + */ public function testRandomScoreWithoutSeed() { $query = new FunctionScore(); $query->setRandomScore(); - $response = $this->type->search($query); + $response = $this->_getIndexForTest()->search($query); $this->assertEquals(2, $response->count()); } + /** + * @group functional + */ public function testScriptScore() { $scriptString = "_score * doc['price'].value"; @@ -191,20 +270,55 @@ class FunctionScoreTest extends BaseTest 'functions' => array( array( 'script_score' => array( - 'script' => $scriptString - ) - ) - ) - ) + 'script' => $scriptString, + ), + ), + ), + ), ); $this->assertEquals($expected, $query->toArray()); - $response = $this->type->search($query); + $response = $this->_getIndexForTest()->search($query); $results = $response->getResults(); // the document the highest price should be scored highest $result0 = $results[0]->getData(); $this->assertEquals("Miller's Field", $result0['name']); } + + /** + * @group functional + */ + public function testSetMinScore() + { + $expected = array( + 'function_score' => array( + 'min_score' => 0.8, + 'functions' => array( + array( + 'gauss' => array( + 'price' => array( + 'origin' => 0, + 'scale' => 10, + ), + ), + ), + ), + ), + ); + + $query = new FunctionScore(); + $query->addDecayFunction(FunctionScore::DECAY_GAUSS, 'price', 0, 10); + $returnedValue = $query->setMinScore(0.8); + + $this->assertEquals($expected, $query->toArray()); + $this->assertInstanceOf('Elastica\Query\FunctionScore', $returnedValue); + + $response = $this->_getIndexForTest()->search($query); + $results = $response->getResults(); + + $this->assertCount(1, $results); + $this->assertEquals(1, $results[0]->getId()); + } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FuzzyLikeThisTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FuzzyLikeThisTest.php index c842c1a8..fe11e788 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FuzzyLikeThisTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FuzzyLikeThisTest.php @@ -1,16 +1,18 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; use Elastica\Index; use Elastica\Query\FuzzyLikeThis; +use Elastica\Test\Base as BaseTest; use Elastica\Type; use Elastica\Type\Mapping; -use Elastica\Test\Base as BaseTest; class FuzzyLikeThisTest extends BaseTest { + /** + * @group functional + */ public function testSearch() { $client = $this->_getClient(); @@ -20,7 +22,7 @@ class FuzzyLikeThisTest extends BaseTest //$index->getSettings()->setNumberOfShards(1); $type = new Type($index, 'helloworldfuzzy'); - $mapping = new Mapping($type , array( + $mapping = new Mapping($type, array( 'email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), )); @@ -35,14 +37,17 @@ class FuzzyLikeThisTest extends BaseTest $index->refresh(); $fltQuery = new FuzzyLikeThis(); - $fltQuery->setLikeText("sample gmail"); - $fltQuery->addFields(array("email","content")); + $fltQuery->setLikeText('sample gmail'); + $fltQuery->addFields(array('email', 'content')); $fltQuery->setMinSimilarity(0.3); $fltQuery->setMaxQueryTerms(3); $resultSet = $type->search($fltQuery); $this->assertEquals(1, $resultSet->count()); } + /** + * @group unit + */ public function testSetPrefixLength() { $query = new FuzzyLikeThis(); @@ -55,6 +60,9 @@ class FuzzyLikeThisTest extends BaseTest $this->assertEquals($length, $data['fuzzy_like_this']['prefix_length']); } + /** + * @group unit + */ public function testAddFields() { $query = new FuzzyLikeThis(); @@ -67,6 +75,9 @@ class FuzzyLikeThisTest extends BaseTest $this->assertEquals($fields, $data['fuzzy_like_this']['fields']); } + /** + * @group unit + */ public function testSetLikeText() { $query = new FuzzyLikeThis(); @@ -79,6 +90,9 @@ class FuzzyLikeThisTest extends BaseTest $this->assertEquals(trim($text), $data['fuzzy_like_this']['like_text']); } + /** + * @group unit + */ public function testSetIgnoreTF() { $query = new FuzzyLikeThis(); @@ -94,6 +108,9 @@ class FuzzyLikeThisTest extends BaseTest $this->assertEquals($ignoreTF, $data['fuzzy_like_this']['ignore_tf']); } + /** + * @group unit + */ public function testSetIgnoreTFDefault() { $query = new FuzzyLikeThis(); @@ -104,6 +121,9 @@ class FuzzyLikeThisTest extends BaseTest $this->assertEquals($defaultIgnoreTF, $data['fuzzy_like_this']['ignore_tf']); } + /** + * @group unit + */ public function testSetMinSimilarity() { $query = new FuzzyLikeThis(); @@ -116,6 +136,9 @@ class FuzzyLikeThisTest extends BaseTest $this->assertEquals($similarity, $data['fuzzy_like_this']['min_similarity']); } + /** + * @group unit + */ public function testSetBoost() { $query = new FuzzyLikeThis(); @@ -128,6 +151,9 @@ class FuzzyLikeThisTest extends BaseTest $this->assertEquals($boost, $data['fuzzy_like_this']['boost']); } + /** + * @group unit + */ public function testAddAnalyzerViasetParam() { $analyzer = 'snowball'; @@ -139,6 +165,9 @@ class FuzzyLikeThisTest extends BaseTest $this->assertEquals($analyzer, $data['fuzzy_like_this']['analyzer']); } + /** + * @group unit + */ public function testSetAnalyzer() { $analyzer = 'snowball'; @@ -150,6 +179,9 @@ class FuzzyLikeThisTest extends BaseTest $this->assertEquals($analyzer, $data['fuzzy_like_this']['analyzer']); } + /** + * @group unit + */ public function testAnalyzerNotPresentInArrayToMaintainDefaultOfField() { $query = new FuzzyLikeThis(); @@ -158,6 +190,9 @@ class FuzzyLikeThisTest extends BaseTest $this->assertArrayNotHasKey('analyzer', $data); } + /** + * @group unit + */ public function testArgArrayFieldsOverwrittenBySetParams() { $query = new FuzzyLikeThis(); @@ -168,6 +203,9 @@ class FuzzyLikeThisTest extends BaseTest $this->assertEquals(200, $data['fuzzy_like_this']['max_query_terms']); } + /** + * @group functional + */ public function testSearchSetAnalyzer() { $client = $this->_getClient(); @@ -177,41 +215,40 @@ class FuzzyLikeThisTest extends BaseTest 'searchAnalyzer' => array( 'type' => 'custom', 'tokenizer' => 'standard', - 'filter' => array('myStopWords') - ) + 'filter' => array('myStopWords'), + ), ), 'filter' => array( 'myStopWords' => array( 'type' => 'stop', - 'stopwords' => array('The') - ) - ) + 'stopwords' => array('The'), + ), + ), )), true); $index->getSettings()->setNumberOfReplicas(0); //$index->getSettings()->setNumberOfShards(1); - + $type = new Type($index, 'helloworldfuzzy'); - $mapping = new Mapping($type , array( + $mapping = new Mapping($type, array( 'email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), )); - + $mapping->setSource(array('enabled' => false)); $type->setMapping($mapping); - $doc = new Document(1000, array('email' => 'testemail@gmail.com', 'content' => 'The Fuzzy Test!')); - $type->addDocument($doc); - - $doc = new Document(1001, array('email' => 'testemail@gmail.com', 'content' => 'Elastica Fuzzy Test')); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1000, array('email' => 'testemail@gmail.com', 'content' => 'The Fuzzy Test!')), + new Document(1001, array('email' => 'testemail@gmail.com', 'content' => 'Elastica Fuzzy Test')), + )); // Refresh index $index->refresh(); $fltQuery = new FuzzyLikeThis(); - $fltQuery->addFields(array("email","content")); - $fltQuery->setLikeText("The"); + $fltQuery->addFields(array('email', 'content')); + $fltQuery->setLikeText('The'); $fltQuery->setMinSimilarity(0.1); $fltQuery->setMaxQueryTerms(3); @@ -225,4 +262,39 @@ class FuzzyLikeThisTest extends BaseTest $resultSet = $type->search($fltQuery); $this->assertEquals(0, $resultSet->count()); } + + /** + * @group functional + */ + public function testNoLikeTextProvidedShouldReturnNoResults() + { + $client = $this->_getClient(); + $index = new Index($client, 'test'); + $index->create(array(), true); + $index->getSettings()->setNumberOfReplicas(0); + + $type = new Type($index, 'helloworldfuzzy'); + $mapping = new Mapping($type, array( + 'email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), + 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), + )); + + $mapping->setSource(array('enabled' => false)); + $type->setMapping($mapping); + + $doc = new Document(1000, array('email' => 'testemail@gmail.com', 'content' => 'This is a sample post. Hello World Fuzzy Like This!')); + $type->addDocument($doc); + + // Refresh index + $index->refresh(); + + $fltQuery = new FuzzyLikeThis(); + $fltQuery->setLikeText(''); + $fltQuery->addFields(array('email', 'content')); + $fltQuery->setMinSimilarity(0.3); + $fltQuery->setMaxQueryTerms(3); + $resultSet = $type->search($fltQuery); + + $this->assertEquals(0, $resultSet->count()); + } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FuzzyTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FuzzyTest.php index 57659293..e9107232 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FuzzyTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/FuzzyTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; @@ -8,6 +7,9 @@ use Elastica\Test\Base as BaseTest; class FuzzyTest extends BaseTest { + /** + * @group unit + */ public function testToArray() { $fuzzy = new Fuzzy(); @@ -16,9 +18,9 @@ class FuzzyTest extends BaseTest 'fuzzy' => array( 'user' => array( 'value' => 'Nicolas', - 'boost' => 1.0 - ) - ) + 'boost' => 1.0, + ), + ), ); $this->assertEquals($expectedArray, $fuzzy->toArray(), 'Deprecated method failed'); @@ -27,8 +29,8 @@ class FuzzyTest extends BaseTest 'fuzzy' => array( 'user' => array( 'value' => 'Nicolas', - ) - ) + ), + ), ); $this->assertEquals($expectedArray, $fuzzy->toArray()); @@ -38,13 +40,16 @@ class FuzzyTest extends BaseTest 'fuzzy' => array( 'user' => array( 'value' => 'Nicolas', - 'boost' => 1.0 - ) - ) + 'boost' => 1.0, + ), + ), ); $this->assertEquals($expectedArray, $fuzzy->toArray()); } + /** + * @group functional + */ public function testQuery() { $client = $this->_getClient(); @@ -52,14 +57,12 @@ class FuzzyTest extends BaseTest $index->create(array(), true); $type = $index->getType('test'); - $doc = new Document(1, array('name' => 'Basel-Stadt')); - $type->addDocument($doc); - $doc = new Document(2, array('name' => 'New York')); - $type->addDocument($doc); - $doc = new Document(3, array('name' => 'Baden')); - $type->addDocument($doc); - $doc = new Document(4, array('name' => 'Baden Baden')); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'Baden')), + new Document(4, array('name' => 'Baden Baden')), + )); $index->refresh(); @@ -73,7 +76,10 @@ class FuzzyTest extends BaseTest $this->assertEquals(2, $resultSet->count()); } - public function testBadArguments () + /** + * @group unit + */ + public function testBadArguments() { $this->setExpectedException('Elastica\Exception\InvalidException'); $query = new Fuzzy(); @@ -88,20 +94,21 @@ class FuzzyTest extends BaseTest $query->setField('name', 'value'); $query->setField('name1', 'value1'); } - - public function testFuzzyWithFacets() { + /** + * @group functional + */ + public function testFuzzyWithFacets() + { $index = $this->_createIndex(); $type = $index->getType('test'); - $doc = new Document(1, array('name' => 'Basel-Stadt')); - $type->addDocument($doc); - $doc = new Document(2, array('name' => 'New York')); - $type->addDocument($doc); - $doc = new Document(3, array('name' => 'Baden')); - $type->addDocument($doc); - $doc = new Document(4, array('name' => 'Baden Baden')); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'Baden')), + new Document(4, array('name' => 'Baden Baden')), + )); $index->refresh(); @@ -109,21 +116,21 @@ class FuzzyTest extends BaseTest $fuzzyQuery = new Fuzzy(); $fuzzyQuery->setField($field, 'Baden'); - + $facet = new \Elastica\Facet\Terms('test'); $facet->setField('name'); - - $query = new \Elastica\Query($fuzzyQuery); - $query->addFacet($facet); + + $query = new \Elastica\Query($fuzzyQuery); + $query->addFacet($facet); $resultSet = $index->search($query); - - // Assert query worked ok + + // Assert query worked ok $this->assertEquals(2, $resultSet->count()); - - // Check Facets - $this->assertTrue($resultSet->hasFacets()); - $facets = $resultSet->getFacets(); - $this->assertEquals(2, $facets['test']['total']); - } + + // Check Facets + $this->assertTrue($resultSet->hasFacets()); + $facets = $resultSet->getFacets(); + $this->assertEquals(2, $facets['test']['total']); + } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasChildTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasChildTest.php index bb1b5b96..a717b1ab 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasChildTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasChildTest.php @@ -1,14 +1,19 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; +use Elastica\Query; use Elastica\Query\HasChild; +use Elastica\Query\Match; use Elastica\Query\MatchAll; use Elastica\Test\Base as BaseTest; +use Elastica\Type\Mapping; class HasChildTest extends BaseTest { + /** + * @group unit + */ public function testToArray() { $q = new MatchAll(); @@ -20,13 +25,16 @@ class HasChildTest extends BaseTest $expectedArray = array( 'has_child' => array( 'query' => $q->toArray(), - 'type' => $type - ) + 'type' => $type, + ), ); $this->assertEquals($expectedArray, $query->toArray()); } + /** + * @group unit + */ public function testSetScope() { $q = new MatchAll(); @@ -42,55 +50,56 @@ class HasChildTest extends BaseTest 'has_child' => array( 'query' => $q->toArray(), 'type' => $type, - '_scope' => $scope - ) + '_scope' => $scope, + ), ); $this->assertEquals($expectedArray, $query->toArray()); } - + + /** + * @group functional + */ public function testTypeInsideHasChildSearch() { - $index = $this->prepareSearchData(); - - $f = new \Elastica\Query\Match(); + $index = $this->_getTestIndex(); + + $f = new Match(); $f->setField('alt.name', 'testname'); $query = new HasChild($f, 'child'); - - $searchQuery = new \Elastica\Query(); + + $searchQuery = new Query(); $searchQuery->setQuery($query); $searchResults = $index->search($searchQuery); - + $this->assertEquals(1, $searchResults->count()); - + $result = $searchResults->current()->getData(); $expected = array('id' => 'parent2', 'user' => 'parent2', 'email' => 'parent2@test.com'); - + $this->assertEquals($expected, $result); - } - - private function prepareSearchData() + } + + protected function _getTestIndex() { - $client = $this->_getClient(); - $index = $client->getIndex('has_child_test'); - $index->create(array(), true); - + $index = $this->_createIndex('has_child_test'); + $parentType = $index->getType('parent'); - + $childType = $index->getType('child'); - $childMapping = new \Elastica\Type\Mapping($childType); + $childMapping = new Mapping($childType); $childMapping->setParent('parent'); $childMapping->send(); - + $altType = $index->getType('alt'); $altDoc = new Document('alt1', array('name' => 'altname')); $altType->addDocument($altDoc); - + $parent1 = new Document('parent1', array('id' => 'parent1', 'user' => 'parent1', 'email' => 'parent1@test.com')); $parentType->addDocument($parent1); $parent2 = new Document('parent2', array('id' => 'parent2', 'user' => 'parent2', 'email' => 'parent2@test.com')); $parentType->addDocument($parent2); - + $child1 = new Document('child1', array('id' => 'child1', 'user' => 'child1', 'email' => 'child1@test.com')); $child1->setParent('parent1'); $childType->addDocument($child1); @@ -100,8 +109,9 @@ class HasChildTest extends BaseTest $child3 = new Document('child3', array('id' => 'child3', 'user' => 'child3', 'email' => 'child3@test.com', 'alt' => array(array('name' => 'testname')))); $child3->setParent('parent2'); $childType->addDocument($child3); - + $index->refresh(); + return $index; } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasParentTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasParentTest.php index d417c887..31a89852 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasParentTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasParentTest.php @@ -1,13 +1,19 @@ <?php - namespace Elastica\Test\Query; +use Elastica\Document; use Elastica\Query\HasParent; +use Elastica\Query\Match; use Elastica\Query\MatchAll; +use Elastica\Search; use Elastica\Test\Base as BaseTest; +use Elastica\Type\Mapping; class HasParentTest extends BaseTest { + /** + * @group unit + */ public function testToArray() { $q = new MatchAll(); @@ -19,13 +25,16 @@ class HasParentTest extends BaseTest $expectedArray = array( 'has_parent' => array( 'query' => $q->toArray(), - 'type' => $type - ) + 'type' => $type, + ), ); $this->assertEquals($expectedArray, $query->toArray()); } + /** + * @group unit + */ public function testSetScope() { $q = new MatchAll(); @@ -41,10 +50,59 @@ class HasParentTest extends BaseTest 'has_parent' => array( 'query' => $q->toArray(), 'type' => $type, - '_scope' => $scope - ) + '_scope' => $scope, + ), ); $this->assertEquals($expectedArray, $query->toArray()); } + + /** + * @group functional + */ + public function testHasParent() + { + $index = $this->_createIndex(); + + $shopType = $index->getType('shop'); + $productType = $index->getType('product'); + $mapping = new Mapping(); + $mapping->setParent('shop'); + $productType->setMapping($mapping); + + $shopType->addDocuments( + array( + new Document('zurich', array('brand' => 'google')), + new Document('london', array('brand' => 'apple')), + ) + ); + + $doc1 = new Document(1, array('device' => 'chromebook')); + $doc1->setParent('zurich'); + + $doc2 = new Document(2, array('device' => 'macmini')); + $doc2->setParent('london'); + + $productType->addDocument($doc1); + $productType->addDocument($doc2); + + $index->refresh(); + + // All documents + $parentQuery = new HasParent(new MatchAll(), $shopType->getName()); + $search = new Search($index->getClient()); + $results = $search->search($parentQuery); + $this->assertEquals(2, $results->count()); + + $match = new Match(); + $match->setField('brand', 'google'); + + $parentQuery = new HasParent($match, $shopType->getName()); + $search = new Search($index->getClient()); + $results = $search->search($parentQuery); + $this->assertEquals(1, $results->count()); + $result = $results->current(); + $data = $result->getData(); + $this->assertEquals($data['device'], 'chromebook'); + } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HighlightTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HighlightTest.php index 4b1b6c5e..c6850019 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HighlightTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HighlightTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; @@ -9,19 +8,20 @@ use Elastica\Test\Base as BaseTest; class HighlightTest extends BaseTest { + /** + * @group functional + */ public function testHightlightSearch() { - $client = $this->_getClient(); - $index = $client->getIndex('test'); - $index->create(array(), true); + $index = $this->_createIndex(); $type = $index->getType('helloworld'); $phrase = 'My name is ruflin'; - $doc = new Document(1, array('id' => 1, 'phrase' => $phrase, 'username' => 'hanswurst', 'test' => array('2', '3', '5'))); - $type->addDocument($doc); - $doc = new Document(2, array('id' => 2, 'phrase' => $phrase, 'username' => 'peter', 'test' => array('2', '3', '5'))); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1, array('id' => 1, 'phrase' => $phrase, 'username' => 'hanswurst', 'test' => array('2', '3', '5'))), + new Document(2, array('id' => 2, 'phrase' => $phrase, 'username' => 'peter', 'test' => array('2', '3', '5'))), + )); $queryString = new QueryString('rufl*'); $query = new Query($queryString); @@ -44,6 +44,5 @@ class HighlightTest extends BaseTest $this->assertEquals(array('phrase' => array(0 => 'My name is <em class="highlight">ruflin</em>')), $highlight); } $this->assertEquals(2, $resultSet->count()); - } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/IdsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/IdsTest.php index d1bf901e..7b39020f 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/IdsTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/IdsTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; @@ -11,11 +10,11 @@ class IdsTest extends BaseTest protected $_index; protected $_type; - public function setUp() + protected function setUp() { - $client = $this->_getClient(); - $index = $client->getIndex('test'); - $index->create(array(), true); + parent::setUp(); + + $index = $this->_createIndex(); $type1 = $index->getType('helloworld1'); $type2 = $index->getType('helloworld2'); @@ -38,13 +37,9 @@ class IdsTest extends BaseTest $this->_index = $index; } - public function tearDown() - { - $client = $this->_getClient(); - $index = $client->getIndex('test'); - $index->delete(); - } - + /** + * @group functional + */ public function testSetIdsSearchSingle() { $query = new Ids(); @@ -55,6 +50,9 @@ class IdsTest extends BaseTest $this->assertEquals(1, $resultSet->count()); } + /** + * @group functional + */ public function testSetIdsSearchArray() { $query = new Ids(); @@ -65,6 +63,9 @@ class IdsTest extends BaseTest $this->assertEquals(2, $resultSet->count()); } + /** + * @group functional + */ public function testAddIdsSearchSingle() { $query = new Ids(); @@ -75,6 +76,9 @@ class IdsTest extends BaseTest $this->assertEquals(1, $resultSet->count()); } + /** + * @group functional + */ public function testComboIdsSearchArray() { $query = new Ids(); @@ -87,6 +91,9 @@ class IdsTest extends BaseTest $this->assertEquals(3, $resultSet->count()); } + /** + * @group functional + */ public function testSetTypeSingleSearchSingle() { $query = new Ids(); @@ -99,6 +106,9 @@ class IdsTest extends BaseTest $this->assertEquals(1, $resultSet->count()); } + /** + * @group functional + */ public function testSetTypeSingleSearchArray() { $query = new Ids(); @@ -111,6 +121,9 @@ class IdsTest extends BaseTest $this->assertEquals(2, $resultSet->count()); } + /** + * @group functional + */ public function testSetTypeSingleSearchSingleDocInOtherType() { $query = new Ids(); @@ -125,6 +138,9 @@ class IdsTest extends BaseTest $this->assertEquals(0, $resultSet->count()); } + /** + * @group functional + */ public function testSetTypeSingleSearchArrayDocInOtherType() { $query = new Ids(); @@ -139,6 +155,9 @@ class IdsTest extends BaseTest $this->assertEquals(1, $resultSet->count()); } + /** + * @group functional + */ public function testSetTypeArraySearchArray() { $query = new Ids(); @@ -151,6 +170,9 @@ class IdsTest extends BaseTest $this->assertEquals(2, $resultSet->count()); } + /** + * @group functional + */ public function testSetTypeArraySearchSingle() { $query = new Ids(); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/ImageTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/ImageTest.php new file mode 100644 index 00000000..989e4e4a --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/ImageTest.php @@ -0,0 +1,159 @@ +<?php +namespace Elastica\Test\Query; + +use Elastica\Document; +use Elastica\Index; +use Elastica\Query\Image; +use Elastica\Test\Base as BaseTest; +use Elastica\Type; +use Elastica\Type\Mapping; + +class ImageTest extends BaseTest +{ + /** + * @var string + */ + protected $_testFileContent; + + protected function setUp() + { + parent::setUp(); + $this->_testFileContent = base64_encode(file_get_contents(BASE_PATH.'/data/test.jpg')); + } + + /** + * @group unit + */ + public function testToArrayFromReference() + { + $client = $this->_getClient(); + $index = new Index($client, 'test'); + $type = new Type($index, 'helloworld'); + $field = 'image'; + + $query = new Image(); + $query->setFieldFeature($field, 'CEDD'); + $query->setFieldHash($field, 'BIT_SAMPLING'); + $query->setFieldBoost($field, 100); + + $query->setImageByReference($field, $index->getName(), $type->getName(), 10); + + $jsonString = '{"image":{"image":{"feature":"CEDD","hash":"BIT_SAMPLING","boost":100,"index":"test","type":"helloworld","id":10,"path":"image"}}}'; + $this->assertEquals($jsonString, json_encode($query->toArray())); + } + + /** + * @group unit + */ + public function testToArrayFromImage() + { + $field = 'image'; + + $query = new Image(); + $query->setFieldFeature($field, 'CEDD'); + $query->setFieldHash($field, 'BIT_SAMPLING'); + $query->setFieldBoost($field, 100); + + $query->setFieldImage($field, BASE_PATH.'/data/test.jpg'); + + $jsonString = '{"image":{"image":{"feature":"CEDD","hash":"BIT_SAMPLING","boost":100,"image":"\/9j\/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP\/sABFEdWNreQABAAQAAAA8AAD\/4QN6aHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI\/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjUtYzAyMSA3OS4xNTQ5MTEsIDIwMTMvMTAvMjktMTE6NDc6MTYgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bXBNTTpPcmlnaW5hbERvY3VtZW50SUQ9InhtcC5kaWQ6OWQ4MjQ5N2MtNzViMS0wYzQ5LTg4ZjMtMDdiNmRhMjU0ZWRhIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjA4NjBGM0Y1QkJGQTExRTM4MjQ0QzMzNjU2MjUxOEJGIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjA4NjBGM0Y0QkJGQTExRTM4MjQ0QzMzNjU2MjUxOEJGIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDQyAoV2luZG93cykiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5ZDgyNDk3Yy03NWIxLTBjNDktODhmMy0wN2I2ZGEyNTRlZGEiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6OWQ4MjQ5N2MtNzViMS0wYzQ5LTg4ZjMtMDdiNmRhMjU0ZWRhIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+\/+4ADkFkb2JlAGTAAAAAAf\/bAIQABgQEBAUEBgUFBgkGBQYJCwgGBggLDAoKCwoKDBAMDAwMDAwQDA4PEA8ODBMTFBQTExwbGxscHx8fHx8fHx8fHwEHBwcNDA0YEBAYGhURFRofHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8f\/8AAEQgAZABkAwERAAIRAQMRAf\/EAKwAAAEFAQEBAQAAAAAAAAAAAAgAAwQFBwYCAQkBAQEAAwEBAAAAAAAAAAAAAAABAgQFAwYQAAEDAgMCBQwOCQQDAAAAAAIBAwQABRESBiEHMUFhExRRcYEisnPDNIQVRRaRodEyQlJikiOzVGYnCLFyo9NklKQlGIIzQ2VTdhcRAAIBAgQEBAYDAQAAAAAAAAABAhEDITESBEFRMgVhcZFCgaHR4SITsVJiFf\/aAAwDAQACEQMRAD8AJyHDhlDYImG1JWwVVUBVVVRTkqge6DC+ztfMH3KgF0GF9na+YPuUAugwvs7XzB9ygF0GF9na+YPuUBR6n1NpDTTAuXUmgdcTFmK22JvuYfFbRMcOVdnLXje3MLa\/JmEpqOZmty32GbiparFGaa24OS1QzXlyNoiJ85a50+5y9q9Tyd7kiva3v6jQ8xwraY\/E5gh9tDrBdxueBP2s6ax74rK6YtXq0DFx2LJjIjzafrAooaJ1sa2LfcU+pUM1eXE0i3nY7jEblwUjyYzqYg62gEK+wnDyV0IzUlVOqPVNMkdBhfZ2vmD7lZFF0GF9na+YPuUBD6JF88c3zIc30fNkyphjnwxwwqkJkHxKP3oO5SoUfoBUAqA47eXr5rSlqEY6C7eJuIwmC2iKJ755xE+AGPZXZWpu9z+qOHU8jzuXNK8Qe813vd2UlV243WaWJmvbOGqcarsQQHsCKVw4Qnclh+UmamLZ3dn3UKQCd1lkprwx42CCnIrpIqqvWSuva7Uve\/Q9la5l0W6rT6hgCSQPiLnlL2iTCth9ss+PqX9aOcv27W725spEEimsDtJpRyvoicaInan2NvJWjf7dKKrB6l8\/uYuDRWaT1fdNN3BJcIlNhxU6XCVcG3hTh\/VcT4Jdhdlali+7bqsiRk0ETZrvBvFsj3KCfORZI5wVdipxKJJxEK7FSu9bmpxTWRtJ1VSbWZSF6b8m8JVA9B8Sj96DuUqAfoDNdab+dKaZvDtnGPIuk6MqDMSNkRtolTHIpuEKKaIqYoOOHHtoCz3bb07frsriMO3yIPm7ms\/SCbLPz2bDLkIuDJx0Bh2u9SHf9VXG5kalHEyYhp8WOwqiOCfKXE+zXzO4u67jkaM5VdTSt3ulAtdrB54E84zBFyUfGIr2wMovUFOHqlX0Gy2ytQ\/08\/oe8I0R3LTIinBW6ZEphGxLthx61Ggiw6Mw8zwIQrXk20zMxXexpMLZLG7xRysSTyShRMERxdouf68MC5a5HcLCi9a45+fP4nhcjTEsdx2oTbuEywun9DIBZcUV4nAVBdRP1kUS7FTt12jcfiWzLgbJXWNghem\/JvCVQPQfEo\/eg7lKgH6AC1m2u6h3hnajeVty63h9hySqZlFDkGpHgvCqCi4VQEvp3dvYNA2a+yLI7KcclxlN1ZTgubY7ZqCjlEMPfLjXncdIvyI8gfbLGR+4W1hzaDzzAn1lMca+b28azinzRoxWISEIUwxw4Vxr642mTxSqQfbCowTI+IqvUVNtYSM4nI70GG39JXNC4W2VcFeoQEhItae9VbMjG50syPdfKNnXtmUOFxxxov1TZPH9FcfaOl2J423+SCVr6A2yF6b8m8JVA9B8Sj96DuUqAfoAOtGF+MtrT\/v3vrXaoDAmRhlRH4x+9fbJsusYqK\/prGSqqBgjgj9ul82YqMm3vZCBeHPHcwVOyoV8zGsJeMX\/AAaGQRdjlNTobctgkJl4BdbVOMTTH2uCvrIyUkmsmbWZbtJjtrMhKbGsWyj2wRxrBmSM73v3lqHpd+Pm+muBDHaHjUcUJxewKVz+43KW6cZYfUwuukfM4PczbHJuuor+XFm3tOyHC6iqPNB7Z1ztjGt1eB5WlWQRdd42yF6b8m8JVA9B8Sj96DuUqA5jeTvJtWhLSzMnMPSn5hmzBjsiioTwgpojhqqIA7Npe1QA2borLf77vMtFwYiOOMx5x3C5TEAkjtoucyTnFTLiRnlEccaoDBqAH7fhpB60X71jihjbLqSJLUU2NS8MMS6gvImxfjJypXG31jTLWsma16NHUh7ud4Q2VUt1wNUtxkqsv7V5kiXFUJE282q7dnvV5Kz2W9UFon08Hy+xjCdDaIdyYkNi82Ym04mIOAqEJIvGhJsrtp1VVkexYDLbRMcajZUVWotV2qzQilXGQLDSJ2grtM1+K2HCS14Xr0barJ\/V+RXJLMH7VWp52qr10lwVajtpzcONjjzbeOOK4cJku0q+d3O4c5apYcvBGpOdXU3XdTo0tPWJX5LeS43DK48K++BtE+jbXl2qq8q11e3bdwhql1S+S4GzZhRVZ21dA9SF6b8m8JVA9B8Sj96DuUqA5feRu0tOvLbGh3CVIhlCcJ+K7GUNjhAoduJiWYUx4NnXoAbdz+p9R6f3m2yyx5riwJVwdt1wgqZLGcwU2+dFtVwE0IEJCTbxLilUBg1AVmpVsnmKYF7Fpy1uN83IbfVEA0NUERxXjIlRE5axkk1R5ElSmIKWoLQ9Y7m9HUSSOhKraEqkQCq4oKl8LBNmbjrlbrt8oOsMY\/NGq7b4Huz6juduPC2z3IxLtVts+1XrguI+1WjC7KHS3EwToXbu8PWxt5EupgnxgFsS9lBr1e8vP3My1y5lCy1e7\/cubYGTd7ia4YBmePsrtQE66ola6UpvCsn6mGLZtu7XdAtoNu66gyOXAVQmIIKhtslxEZcBmnFh2qcvDXT23b6PVcz4I2LdmmLNTrqnuKgIXpvybwlUD0HxKP3oO5SoB+gAo0Qf43WlPvC\/9c9VAa9QGC79NZjcLoOnIp5oVtJHJypwHKVO1DlRoVxX5S8lcff39UtCyWZq35VwMrLUN3Pmbc235yJ0xYhxDxJxTNcoNtn75MVWvXbbqcaLqRhCbQTunN2OloOmIlquFriy3hHnJTjrYuKr57XMDVMcEXYmHEldCduM+pI29KeZIa3XbvWjQwsETMm3aGZPYVVSvJbS1\/VE\/XHkYlvp3zav3fa8LTWlQtsK2JDjyBZKIiqrjqmhe8NtPgJxV7xilkZJULrcV+Ya86v1H6ranjRxnyGnHrdPiCTYuKymZxpxsiPAsmJCQrhs4KpTfKAVAQvTfk3hKoHoPiUfvQdylQD9ABHoYvxxtP8A7E\/9c9VAW28PV7WltNPzhUSnO\/QW5lfhPmi5VVPignbFyJWvub6twb48DCc9KqChcZZqpm44rjpkRuOltIzJcxEvKSrjXz0at1ZpGk\/l10Ot0vD2sZ7eMO2kUe0iSYoclUwdewX\/AMQrkH5Sr1K7Gzte5nvZhxCMroGyKgOe1ToPR2o4stLzZ4cx6QwrBynGGykICIuXK8qZxUVXEcF2LQAafl6JR3zaYRSXY7KDMvCuEV5NvXwoA7KAVAQvTfk3hKoHoPiUfvQdylQD9AA9oUvx0tKfeN\/656qAjN48yyXqZJ09emnIc+P9JalLATNvKirJil71xMVyOBwphtTai15XbMbkaSMZxTWJiZ7utS3a+x7PazbkdKcQFliuVGWse3dMC29oO3BMcV2Vzf8Anzi+aNd2WFhp2w27T9jhWW3BzcKA0LLI8aonCRdUiXElXq11IxSVEbKVFQsayKKgESISKK7UXYqUAAmu7A9uz1+o2K\/xJsq2yykQXoh85IikJqoty21Hm0MUVRIcxIqcOHBQBhblNb3bW+7i16juwMNz5ZPg8MUSFr6F82kVBMjVMUDFdvDQHc0BC9N+TeEqgeg+JR+9B3KVAP0ADOgy\/Ha0J95H\/rnqoDT1Fpiwajt62+9wm50VVQxFxFQgNOA2zFUNs04iBUWoCn0Xu4tGkpEx+HMmTSlZRBZ7ovkyCYrkBzKJqir8dSXZw0B1dAKgFQHl1VFo1HhQVVOvhQH567obLA1XvYsNnvIrJhzpjzs0CVfpUaBx9RNeHAyDAuSgP0Et9ut9tiNwrdFZhQ2UwajR2xaaBFXHtQBEFNvUSgJFAQvTfk3hKoHoPiUfvQdylQD9AABrKPedG7y7o2RlBu1tujs6A+qIiqJPq8w+CFsICEk9tKoO2\/yy3qIiY+aNibV6M5t5f9+oD5\/lpvV\/6j+Wc\/f0B5X82u9Xi80fyzn7+gPJfm43qim3zR\/LOfv6AZP83+9ZODzP\/LO\/v6Ag3P8ANvvZm2+TC5y2xkktk0siPHNHQQ0wUm1N0xQuoqitARPyqafn3XfDbJ0dslhWRqRJmPInaijjJstipcGYzc2Jx4L1KAO2gFQEL035N4SqBmJ546KzzfR+byDkzZ8cMEwxwoQe\/vf8N+0oU5bWfqdjH9c\/V7NgvRfO3NZsMdvN8\/twx4cKA5j8BuP1K\/pKA+fgL9yv6OgF+An3J\/o6A8r\/APAOP1I7PQ6A8F\/j1x+o\/Z6FQHgv8deP1F7PQqA7rRnq\/wCal9S\/MfmrOubzRzfMc5gmObo\/a5sOrtoC\/wD73\/DftKAX97\/hv2lARP7p50\/4Of5j5eTJn9nHGhD\/2Q=="}}}'; + $this->assertEquals($jsonString, json_encode($query->toArray())); + } + + /** + * @group functional + */ + public function testFromReference() + { + $this->markTestSkipped('Tests skipped as plugin not working properly with ES 1.6.0. See https://github.com/ruflin/Elastica/pull/881'); + $field = 'image'; + + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + + $type = $index->getType('test'); + + $mapping = new Mapping($type, array( + $field => array( + 'type' => 'image', + 'store' => false, + 'include_in_all' => false, + 'feature' => array( + 'CEDD' => array( + 'hash' => 'BIT_SAMPLING', + ), + ), + ), + ) + ); + + $type->setMapping($mapping); + + $type->addDocuments(array( + new Document(1, array($field => $this->_testFileContent)), + new Document(2, array($field => $this->_testFileContent)), + new Document(3, array($field => $this->_testFileContent)), + )); + + $index->refresh(); + + $query = new Image(); + $query->setFieldFeature($field, 'CEDD'); + $query->setFieldHash($field, 'BIT_SAMPLING'); + $query->setFieldBoost($field, 100); + $query->setImageByReference($field, $index->getName(), $type->getName(), 1); + + $resultSet = $index->search($query); + $this->assertEquals(3, $resultSet->count()); + } + + /** + * @group functional + */ + public function testFromImage() + { + $this->markTestSkipped('Tests skipped as plugin not working properly with ES 1.6.0. See https://github.com/ruflin/Elastica/pull/881'); + + $field = 'image'; + + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + + $type = $index->getType('test'); + + $mapping = new Mapping($type, array( + $field => array( + 'type' => 'image', + 'store' => false, + 'include_in_all' => false, + 'feature' => array( + 'CEDD' => array( + 'hash' => 'BIT_SAMPLING', + ), + ), + ), + ) + ); + + $type->setMapping($mapping); + + $type->addDocuments(array( + new Document(1, array($field => $this->_testFileContent)), + new Document(2, array($field => $this->_testFileContent)), + new Document(3, array($field => $this->_testFileContent)), + )); + + $index->refresh(); + + $query = new Image(); + $query->setFieldFeature($field, 'CEDD'); + $query->setFieldHash($field, 'BIT_SAMPLING'); + $query->setFieldBoost($field, 100); + $query->setFieldImage($field, BASE_PATH.'/data/test.jpg'); + + $resultSet = $index->search($query); + $this->assertEquals(3, $resultSet->count()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchAllTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchAllTest.php index 3731e659..7eb0fae0 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchAllTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchAllTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; @@ -9,6 +8,9 @@ use Elastica\Test\Base as BaseTest; class MatchAllTest extends BaseTest { + /** + * @group unit + */ public function testToArray() { $query = new MatchAll(); @@ -18,10 +20,13 @@ class MatchAllTest extends BaseTest $this->assertEquals($expectedArray, $query->toArray()); } + /** + * @group functional + */ public function testMatchAllIndicesTypes() { - $index1 = $this->_createIndex('test1'); - $index2 = $this->_createIndex('test2'); + $index1 = $this->_createIndex(); + $index2 = $this->_createIndex(); $client = $index1->getClient(); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchTest.php index ed164663..98fdf26a 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchTest.php @@ -1,13 +1,17 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; use Elastica\Query\Match; +use Elastica\Query\MatchPhrase; +use Elastica\Query\MatchPhrasePrefix; use Elastica\Test\Base as BaseTest; class MatchTest extends BaseTest { + /** + * @group unit + */ public function testToArray() { $field = 'test'; @@ -46,14 +50,17 @@ class MatchTest extends BaseTest 'fuzziness' => $fuzziness, 'fuzzy_rewrite' => $fuzzyRewrite, 'prefix_length' => $prefixLength, - 'max_expansions' => $maxExpansions - ) - ) + 'max_expansions' => $maxExpansions, + ), + ), ); $this->assertEquals($expectedArray, $query->toArray()); } + /** + * @group functional + */ public function testMatch() { $client = $this->_getClient(); @@ -61,14 +68,75 @@ class MatchTest extends BaseTest $index->create(array(), true); $type = $index->getType('test'); - $doc = new Document(1, array('name' => 'Basel-Stadt')); - $type->addDocument($doc); - $doc = new Document(2, array('name' => 'New York')); - $type->addDocument($doc); - $doc = new Document(3, array('name' => 'New Hampshire')); - $type->addDocument($doc); - $doc = new Document(4, array('name' => 'Basel Land')); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'New Hampshire')), + new Document(4, array('name' => 'Basel Land')), + )); + + $index->refresh(); + + $field = 'name'; + $operator = 'or'; + + $query = new Match(); + $query->setFieldQuery($field, 'Basel New'); + $query->setFieldOperator($field, $operator); + + $resultSet = $index->search($query); + + $this->assertEquals(4, $resultSet->count()); + } + + /** + * @group functional + */ + public function testMatchSetFieldBoost() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('test'); + + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'New Hampshire')), + new Document(4, array('name' => 'Basel Land')), + )); + + $index->refresh(); + + $field = 'name'; + $operator = 'or'; + + $query = new Match(); + $query->setFieldQuery($field, 'Basel New'); + $query->setFieldOperator($field, $operator); + $query->setFieldBoost($field, 1.2); + + $resultSet = $index->search($query); + + $this->assertEquals(4, $resultSet->count()); + } + + /** + * @group functional + */ + public function testMatchSetFieldBoostWithString() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('test'); + + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'New Hampshire')), + new Document(4, array('name' => 'Basel Land')), + )); $index->refresh(); @@ -78,22 +146,28 @@ class MatchTest extends BaseTest $query = new Match(); $query->setFieldQuery($field, 'Basel New'); $query->setFieldOperator($field, $operator); + $query->setFieldBoost($field, '1.2'); $resultSet = $index->search($query); $this->assertEquals(4, $resultSet->count()); } + /** + * @group functional + */ public function testMatchZeroTerm() { $client = $this->_getClient(); $index = $client->getIndex('test'); $index->create(array(), true); $type = $index->getType('test'); - $doc = new Document(1, array('name' => 'Basel-Stadt')); - $type->addDocument($doc); - $doc = new Document(2, array('name' => 'New York')); - $type->addDocument($doc); + + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + )); + $index->refresh(); $query = new Match(); @@ -105,6 +179,9 @@ class MatchTest extends BaseTest $this->assertEquals(2, $resultSet->count()); } + /** + * @group functional + */ public function testMatchPhrase() { $client = $this->_getClient(); @@ -112,14 +189,12 @@ class MatchTest extends BaseTest $index->create(array(), true); $type = $index->getType('test'); - $doc = new Document(1, array('name' => 'Basel-Stadt')); - $type->addDocument($doc); - $doc = new Document(2, array('name' => 'New York')); - $type->addDocument($doc); - $doc = new Document(3, array('name' => 'New Hampshire')); - $type->addDocument($doc); - $doc = new Document(4, array('name' => 'Basel Land')); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'New Hampshire')), + new Document(4, array('name' => 'Basel Land')), + )); $index->refresh(); @@ -135,6 +210,38 @@ class MatchTest extends BaseTest $this->assertEquals(1, $resultSet->count()); } + /** + * @group functional + */ + public function testMatchPhraseAlias() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('test'); + + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'New Hampshire')), + new Document(4, array('name' => 'Basel Land')), + )); + + $index->refresh(); + + $field = 'name'; + + $query = new MatchPhrase(); + $query->setFieldQuery($field, 'New York'); + + $resultSet = $index->search($query); + + $this->assertEquals(1, $resultSet->count()); + } + + /** + * @group functional + */ public function testMatchPhrasePrefix() { $client = $this->_getClient(); @@ -142,14 +249,12 @@ class MatchTest extends BaseTest $index->create(array(), true); $type = $index->getType('test'); - $doc = new Document(1, array('name' => 'Basel-Stadt')); - $type->addDocument($doc); - $doc = new Document(2, array('name' => 'New York')); - $type->addDocument($doc); - $doc = new Document(3, array('name' => 'New Hampshire')); - $type->addDocument($doc); - $doc = new Document(4, array('name' => 'Basel Land')); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'New Hampshire')), + new Document(4, array('name' => 'Basel Land')), + )); $index->refresh(); @@ -164,24 +269,71 @@ class MatchTest extends BaseTest $this->assertEquals(2, $resultSet->count()); } - - + + /** + * @group functional + */ + public function testMatchPhrasePrefixAlias() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('test'); + + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'New Hampshire')), + new Document(4, array('name' => 'Basel Land')), + )); + + $index->refresh(); + + $field = 'name'; + + $query = new MatchPhrasePrefix(); + $query->setFieldQuery($field, 'New'); + + $resultSet = $index->search($query); + + $this->assertEquals(2, $resultSet->count()); + } + + /** + * @group unit + */ public function testMatchFuzzinessType() { $field = 'test'; $query = new Match(); - - $fuzziness = "AUTO"; + + $fuzziness = 'AUTO'; $query->setFieldFuzziness($field, $fuzziness); - - $parameters = $query->getParam($field); - $this->assertEquals($fuzziness, $parameters['fuzziness']); - - + + $parameters = $query->getParam($field); + $this->assertEquals($fuzziness, $parameters['fuzziness']); + $fuzziness = 0.3; $query->setFieldFuzziness($field, $fuzziness); - - $parameters = $query->getParam($field); - $this->assertEquals($fuzziness, $parameters['fuzziness']); + + $parameters = $query->getParam($field); + $this->assertEquals($fuzziness, $parameters['fuzziness']); + } + + /** + * @group unit + */ + public function testConstruct() + { + $match = new Match(null, 'values'); + $this->assertEquals(array('match' => array()), $match->toArray()); + + $match = new Match('field', null); + $this->assertEquals(array('match' => array()), $match->toArray()); + + $match1 = new Match('field', 'values'); + $match2 = new Match(); + $match2->setField('field', 'values'); + $this->assertEquals($match1->toArray(), $match2->toArray()); } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MoreLikeThisTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MoreLikeThisTest.php index b352e23a..5dfe9379 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MoreLikeThisTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MoreLikeThisTest.php @@ -1,17 +1,19 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; use Elastica\Index; use Elastica\Query; use Elastica\Query\MoreLikeThis; +use Elastica\Test\Base as BaseTest; use Elastica\Type; use Elastica\Type\Mapping; -use Elastica\Test\Base as BaseTest; class MoreLikeThisTest extends BaseTest { + /** + * @group functional + */ public function testSearch() { $client = $this->_getClient(); @@ -21,7 +23,7 @@ class MoreLikeThisTest extends BaseTest //$index->getSettings()->setNumberOfShards(1); $type = new Type($index, 'helloworldmlt'); - $mapping = new Mapping($type , array( + $mapping = new Mapping($type, array( 'email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), )); @@ -40,7 +42,7 @@ class MoreLikeThisTest extends BaseTest $mltQuery = new MoreLikeThis(); $mltQuery->setLikeText('fake gmail sample'); - $mltQuery->setFields(array('email','content')); + $mltQuery->setFields(array('email', 'content')); $mltQuery->setMaxQueryTerms(1); $mltQuery->setMinDocFrequency(1); $mltQuery->setMinTermFrequency(1); @@ -54,6 +56,9 @@ class MoreLikeThisTest extends BaseTest $this->assertEquals(2, $resultSet->count()); } + /** + * @group unit + */ public function testSetFields() { $query = new MoreLikeThis(); @@ -65,6 +70,22 @@ class MoreLikeThisTest extends BaseTest $this->assertEquals($fields, $data['more_like_this']['fields']); } + /** + * @group unit + */ + public function testSetIds() + { + $query = new MoreLikeThis(); + $ids = array(1, 2, 3); + $query->setIds($ids); + + $data = $query->toArray(); + $this->assertEquals($ids, $data['more_like_this']['ids']); + } + + /** + * @group unit + */ public function testSetLikeText() { $query = new MoreLikeThis(); @@ -74,6 +95,9 @@ class MoreLikeThisTest extends BaseTest $this->assertEquals('hello world', $data['more_like_this']['like_text']); } + /** + * @group unit + */ public function testSetBoost() { $query = new MoreLikeThis(); @@ -84,6 +108,9 @@ class MoreLikeThisTest extends BaseTest $this->assertEquals($boost, $query->getParam('boost')); } + /** + * @group unit + */ public function testSetMaxQueryTerms() { $query = new MoreLikeThis(); @@ -94,6 +121,9 @@ class MoreLikeThisTest extends BaseTest $this->assertEquals($max, $query->getParam('max_query_terms')); } + /** + * @group unit + */ public function testSetPercentTermsToMatch() { $query = new MoreLikeThis(); @@ -104,6 +134,22 @@ class MoreLikeThisTest extends BaseTest $this->assertEquals($match, $query->getParam('percent_terms_to_match')); } + /** + * @group unit + */ + public function testSetMinimumShouldMatch() + { + $query = new MoreLikeThis(); + + $match = '80%'; + $query->setMinimumShouldMatch($match); + + $this->assertEquals($match, $query->getParam('minimum_should_match')); + } + + /** + * @group unit + */ public function testSetMinDocFrequency() { $query = new MoreLikeThis(); @@ -114,6 +160,9 @@ class MoreLikeThisTest extends BaseTest $this->assertEquals($freq, $query->getParam('min_doc_freq')); } + /** + * @group unit + */ public function testSetMaxDocFrequency() { $query = new MoreLikeThis(); @@ -124,6 +173,9 @@ class MoreLikeThisTest extends BaseTest $this->assertEquals($freq, $query->getParam('max_doc_freq')); } + /** + * @group unit + */ public function testSetMinWordLength() { $query = new MoreLikeThis(); @@ -134,6 +186,9 @@ class MoreLikeThisTest extends BaseTest $this->assertEquals($length, $query->getParam('min_word_length')); } + /** + * @group unit + */ public function testSetMaxWordLength() { $query = new MoreLikeThis(); @@ -144,6 +199,9 @@ class MoreLikeThisTest extends BaseTest $this->assertEquals($length, $query->getParam('max_word_length')); } + /** + * @group unit + */ public function testSetBoostTerms() { $query = new MoreLikeThis(); @@ -154,6 +212,9 @@ class MoreLikeThisTest extends BaseTest $this->assertEquals($boost, $query->getParam('boost_terms')); } + /** + * @group unit + */ public function testSetAnalyzer() { $query = new MoreLikeThis(); @@ -164,6 +225,9 @@ class MoreLikeThisTest extends BaseTest $this->assertEquals($analyzer, $query->getParam('analyzer')); } + /** + * @group unit + */ public function testSetStopWords() { $query = new MoreLikeThis(); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MultiMatchTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MultiMatchTest.php index 78a8a8fe..e32f91af 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MultiMatchTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MultiMatchTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; @@ -22,114 +21,142 @@ class MultiMatchTest extends BaseTest array('id' => 4, 'name' => 'John', 'last_name' => 'not Doe', 'full_name' => 'John not Doe'), ); - protected function setUp() - { - $this->index = $this->_generateIndex(); - $this->multiMatch = new MultiMatch(); - } - + /** + * @group functional + */ public function testMinimumShouldMatch() { - $this->multiMatch->setQuery('Tristan Maindron'); - $this->multiMatch->setFields(array('full_name', 'name')); - $this->multiMatch->setMinimumShouldMatch(2); - $resultSet = $this->_getResults(); + $multiMatch = new MultiMatch(); + $multiMatch->setQuery('Tristan Maindron'); + $multiMatch->setFields(array('full_name', 'name')); + $multiMatch->setMinimumShouldMatch('2<100%'); + $resultSet = $this->_getResults($multiMatch); $this->assertEquals(1, $resultSet->count()); } + /** + * @group functional + */ public function testAndOperator() { - $this->multiMatch->setQuery('Monique Maindron'); - $this->multiMatch->setFields(array('full_name', 'name')); - $this->multiMatch->setOperator(MultiMatch::OPERATOR_AND); - $resultSet = $this->_getResults(); + $multiMatch = new MultiMatch(); + $multiMatch->setQuery('Monique Maindron'); + $multiMatch->setFields(array('full_name', 'name')); + $multiMatch->setOperator(MultiMatch::OPERATOR_AND); + $resultSet = $this->_getResults($multiMatch); $this->assertEquals(1, $resultSet->count()); } + /** + * @group functional + */ public function testType() { - $this->multiMatch->setQuery('Trist'); - $this->multiMatch->setFields(array('full_name', 'name')); - $this->multiMatch->setType(MultiMatch::TYPE_PHRASE_PREFIX); - $resultSet = $this->_getResults(); + $multiMatch = new MultiMatch(); + $multiMatch->setQuery('Trist'); + $multiMatch->setFields(array('full_name', 'name')); + $multiMatch->setType(MultiMatch::TYPE_PHRASE_PREFIX); + $resultSet = $this->_getResults($multiMatch); $this->assertEquals(1, $resultSet->count()); } + /** + * @group functional + */ public function testFuzzy() { - $this->multiMatch->setQuery('Tritsan'); // Mispell on purpose - $this->multiMatch->setFields(array('full_name', 'name')); - $this->multiMatch->setFuzziness(2); - $resultSet = $this->_getResults(); + $multiMatch = new MultiMatch(); + $multiMatch->setQuery('Tritsan'); // Mispell on purpose + $multiMatch->setFields(array('full_name', 'name')); + $multiMatch->setFuzziness(2); + $resultSet = $this->_getResults($multiMatch); $this->assertEquals(1, $resultSet->count()); - $this->multiMatch->setQuery('Tritsan'); // Mispell on purpose - $this->multiMatch->setFields(array('full_name', 'name')); - $this->multiMatch->setFuzziness(0); - $resultSet = $this->_getResults(); + $multiMatch = new MultiMatch(); + $multiMatch->setQuery('Tritsan'); // Mispell on purpose + $multiMatch->setFields(array('full_name', 'name')); + $multiMatch->setFuzziness(0); + $resultSet = $this->_getResults($multiMatch); $this->assertEquals(0, $resultSet->count()); } + /** + * @group functional + */ public function testFuzzyWithOptions1() { // Here Elasticsearch will not accept mispells // on the first 6 letters. - $this->multiMatch->setQuery('Tritsan'); // Mispell on purpose - $this->multiMatch->setFields(array('full_name', 'name')); - $this->multiMatch->setFuzziness(2); - $this->multiMatch->setPrefixLength(6); - $resultSet = $this->_getResults(); + $multiMatch = new MultiMatch(); + $multiMatch->setQuery('Tritsan'); // Mispell on purpose + $multiMatch->setFields(array('full_name', 'name')); + $multiMatch->setFuzziness(2); + $multiMatch->setPrefixLength(6); + $resultSet = $this->_getResults($multiMatch); - $this->assertEquals(0, $resultSet->count()); + $this->assertEquals(0, $resultSet->count()); } - - public function testFuzzyWithOptions2() { + /** + * @group functional + */ + public function testFuzzyWithOptions2() + { // Here with a 'M' search we should hit 'Moraes' first // and then stop because MaxExpansion = 1. // If MaxExpansion was set to 2, we could hit "Maindron" too. - $this->multiMatch->setQuery('M'); - $this->multiMatch->setFields(array('name')); - $this->multiMatch->setType(MultiMatch::TYPE_PHRASE_PREFIX); - $this->multiMatch->setPrefixLength(0); - $this->multiMatch->setMaxExpansions(1); - $resultSet = $this->_getResults(); + $multiMatch = new MultiMatch(); + $multiMatch->setQuery('M'); + $multiMatch->setFields(array('name')); + $multiMatch->setType(MultiMatch::TYPE_PHRASE_PREFIX); + $multiMatch->setPrefixLength(0); + $multiMatch->setMaxExpansions(1); + $resultSet = $this->_getResults($multiMatch); $this->assertEquals(1, $resultSet->count()); } + /** + * @group functional + */ public function testZeroTerm() { - $this->multiMatch->setQuery('not'); // This is a stopword. - $this->multiMatch->setFields(array('full_name', 'last_name')); - $this->multiMatch->setZeroTermsQuery(MultiMatch::ZERO_TERM_NONE); - $this->multiMatch->setAnalyzer('stops'); - $resultSet = $this->_getResults(); + $multiMatch = new MultiMatch(); + $multiMatch->setQuery('not'); // This is a stopword. + $multiMatch->setFields(array('full_name', 'last_name')); + $multiMatch->setZeroTermsQuery(MultiMatch::ZERO_TERM_NONE); + $multiMatch->setAnalyzer('stops'); + $resultSet = $this->_getResults($multiMatch); $this->assertEquals(0, $resultSet->count()); - $this->multiMatch->setZeroTermsQuery(MultiMatch::ZERO_TERM_ALL); - $resultSet = $this->_getResults(); + $multiMatch->setZeroTermsQuery(MultiMatch::ZERO_TERM_ALL); + $resultSet = $this->_getResults($multiMatch); $this->assertEquals(4, $resultSet->count()); } + /** + * @group functional + */ public function testBaseMultiMatch() { - $this->multiMatch->setQuery('Rodolfo'); - $this->multiMatch->setFields(array('name', 'last_name')); - $resultSet = $this->_getResults(); + $multiMatch = new MultiMatch(); + $multiMatch->setQuery('Rodolfo'); + $multiMatch->setFields(array('name', 'last_name')); + $resultSet = $this->_getResults($multiMatch); $this->assertEquals(1, $resultSet->count()); - $this->multiMatch->setQuery('Moraes'); - $this->multiMatch->setFields(array('name', 'last_name')); - $resultSet = $this->_getResults(); + $multiMatch = new MultiMatch(); + $multiMatch->setQuery('Moraes'); + $multiMatch->setFields(array('name', 'last_name')); + $resultSet = $this->_getResults($multiMatch); $this->assertEquals(1, $resultSet->count()); } @@ -137,9 +164,9 @@ class MultiMatchTest extends BaseTest /** * Executes the query with the current multimatch. */ - private function _getResults() + private function _getResults(MultiMatch $multiMatch) { - return $this->index->search(new Query($this->multiMatch)); + return $this->_generateIndex()->search(new Query($multiMatch)); } /** @@ -154,21 +181,21 @@ class MultiMatchTest extends BaseTest 'analysis' => array( 'analyzer' => array( 'noStops' => array( - 'type' => 'standard', - 'stopwords' => '_none_' + 'type' => 'standard', + 'stopwords' => '_none_', ), 'stops' => array( - 'type' => 'standard', - 'stopwords' => array('not') + 'type' => 'standard', + 'stopwords' => array('not'), ), ), - ) + ), ), true); $type = $index->getType('test'); $mapping = new Mapping($type, array( - 'name' => array('type' => 'string', 'store' => 'no', 'analyzer' => 'noStops'), + 'name' => array('type' => 'string', 'store' => 'no', 'analyzer' => 'noStops'), 'last_name' => array('type' => 'string', 'store' => 'no', 'analyzer' => 'noStops'), 'full_name' => array('type' => 'string', 'store' => 'no', 'analyzer' => 'noStops'), )); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/NestedTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/NestedTest.php index 310a728b..1b5fc368 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/NestedTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/NestedTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Query\Nested; @@ -8,6 +7,9 @@ use Elastica\Test\Base as BaseTest; class NestedTest extends BaseTest { + /** + * @group unit + */ public function testSetQuery() { $nested = new Nested(); @@ -20,7 +22,7 @@ class NestedTest extends BaseTest 'nested' => array( 'query' => $queryString->toArray(), 'path' => $path, - ) + ), ); $this->assertEquals($expected, $nested->toArray()); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/PostFilterTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/PostFilterTest.php index 16b7e07b..178c803e 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/PostFilterTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/PostFilterTest.php @@ -1,61 +1,48 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; use Elastica\Filter\Term; -use Elastica\Index; -use Elastica\Query\Match; use Elastica\Query; +use Elastica\Query\Match; use Elastica\Test\Base as BaseTest; class PostFilterTest extends BaseTest { - /** - * @var Index - */ - protected $_index; - - protected function setUp() + protected function _getTestIndex() { - parent::setUp(); - $this->_index = $this->_createIndex("query"); + $index = $this->_createIndex(); $docs = array( - new Document("1", array("color" => "green", "make" => "ford")), - new Document("2", array("color" => "blue", "make" => "volvo")), - new Document("3", array("color" => "red", "make" => "ford")), - new Document("4", array("color" => "green", "make" => "renault")), + new Document(1, array('color' => 'green', 'make' => 'ford')), + new Document(2, array('color' => 'blue', 'make' => 'volvo')), + new Document(3, array('color' => 'red', 'make' => 'ford')), + new Document(4, array('color' => 'green', 'make' => 'renault')), ); - $this->_index->getType("test")->addDocuments($docs); - $this->_index->refresh(); + $index->getType('test')->addDocuments($docs); + $index->refresh(); + return $index; } - protected function tearDown() - { - parent::tearDown(); - if ($this->_index instanceof Index) { - $this->_index->delete(); - } - } - + /** + * @group unit + */ public function testToArray() { $query = new Query(); $post_filter = new Term(array('color' => 'green')); - $query->setPostFilter($post_filter->toArray()); + $query->setPostFilter($post_filter); $data = $query->toArray(); $this->assertArrayHasKey('post_filter', $data); $this->assertEquals(array('term' => array('color' => 'green')), $data['post_filter']); - - $query->setPostFilter(array()); - - $this->assertArrayNotHasKey('post_filter', $query->toArray()); } + /** + * @group functional + */ public function testQuery() { $query = new Query(); @@ -68,16 +55,10 @@ class PostFilterTest extends BaseTest $filter = new Term(); $filter->setTerm('color', 'green'); - $query->setPostFilter($filter->toArray()); + $query->setPostFilter($filter); - $results = $this->_index->search($query); + $results = $this->_getTestIndex()->search($query); $this->assertEquals(1, $results->getTotalHits()); - - } - - protected function _createIndex($name = 'test', $delete = true, $shards = 1) - { - return parent::_createIndex('test_postfilter_' . $name, $delete, $shards); } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/PrefixTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/PrefixTest.php index e6852c2e..e12ead05 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/PrefixTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/PrefixTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Query\Prefix; @@ -7,7 +6,9 @@ use Elastica\Test\Base as BaseTest; class PrefixTest extends BaseTest { - + /** + * @group unit + */ public function testToArray() { $query = new Prefix(); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/QueryStringTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/QueryStringTest.php index 059bad2d..5b549a30 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/QueryStringTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/QueryStringTest.php @@ -1,22 +1,22 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; -use Elastica\Index; -use Elastica\Type; use Elastica\Query\QueryString; use Elastica\Test\Base as BaseTest; class QueryStringTest extends BaseTest { + /** + * @group unit + */ public function testSearchMultipleFields() { $str = md5(rand()); $query = new QueryString($str); $expected = array( - 'query' => $str + 'query' => $str, ); $this->assertEquals(array('query_string' => $expected), $query->toArray()); @@ -39,20 +39,17 @@ class QueryStringTest extends BaseTest } } + /** + * @group functional + */ public function testSearch() { - $client = $this->_getClient(); - $index = new Index($client, 'test'); - $index->create(array(), true); + $index = $this->_createIndex(); $index->getSettings()->setNumberOfReplicas(0); - //$index->getSettings()->setNumberOfShards(1); - - $type = new Type($index, 'helloworld'); + $type = $index->getType('helloworld'); $doc = new Document(1, array('email' => 'test@test.com', 'username' => 'hanswurst', 'test' => array('2', '3', '5'))); $type->addDocument($doc); - - // Refresh index $index->refresh(); $queryString = new QueryString('test*'); @@ -62,7 +59,9 @@ class QueryStringTest extends BaseTest } /** - * Tests if search in multiple fields is possible + * Tests if search in multiple fields is possible. + * + * @group functional */ public function testSearchFields() { @@ -82,6 +81,9 @@ class QueryStringTest extends BaseTest $this->assertEquals(1, $resultSet->count()); } + /** + * @group unit + */ public function testSetDefaultOperator() { $operator = 'AND'; @@ -93,6 +95,9 @@ class QueryStringTest extends BaseTest $this->assertEquals($data['query_string']['default_operator'], $operator); } + /** + * @group unit + */ public function testSetDefaultField() { $default = 'field1'; @@ -104,18 +109,22 @@ class QueryStringTest extends BaseTest $this->assertEquals($data['query_string']['default_field'], $default); } + /** + * @group unit + */ public function testSetRewrite() { - $rewrite = 'scoring_boolean'; - $query = new QueryString('test'); - $query->setRewrite($rewrite); + $rewrite = 'scoring_boolean'; + $query = new QueryString('test'); + $query->setRewrite($rewrite); - $data = $query->toArray(); + $data = $query->toArray(); - $this->assertEquals($data['query_string']['rewrite'], $rewrite); + $this->assertEquals($data['query_string']['rewrite'], $rewrite); } /** + * @group unit * @expectedException \Elastica\Exception\InvalidException */ public function testSetQueryInvalid() @@ -123,4 +132,58 @@ class QueryStringTest extends BaseTest $query = new QueryString(); $query->setQuery(array()); } + + /** + * @group unit + */ + public function testSetTimezone() + { + $timezone = 'Europe/Paris'; + $text = 'date:[2012 TO 2014]'; + + $query = new QueryString($text); + $query->setTimezone($timezone); + + $expected = array( + 'query_string' => array( + 'query' => $text, + 'time_zone' => $timezone, + ), + ); + + $this->assertEquals($expected, $query->toArray()); + $this->assertInstanceOf('Elastica\Query\QueryString', $query->setTimezone($timezone)); + } + + /** + * @group unit + */ + public function testSetPhraseSlop() + { + $phraseSlop = 9; + + $query = new QueryString('test'); + $query->setPhraseSlop($phraseSlop); + + $data = $query->toArray(); + $this->assertEquals($phraseSlop, $data['query_string']['phrase_slop']); + } + + /** + * @group functional + */ + public function testSetBoost() + { + $index = $this->_createIndex(); + $query = new QueryString('test'); + $query->setBoost(9.3); + + $doc = new Document('', array('name' => 'test')); + $index->getType('test')->addDocument($doc); + $index->refresh(); + + $resultSet = $index->search($query); + + $this->assertEquals(1, $resultSet->count()); + } } diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RangeTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RangeTest.php index 4cd75bc8..108ef0c9 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RangeTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RangeTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; @@ -8,6 +7,9 @@ use Elastica\Test\Base as BaseTest; class RangeTest extends BaseTest { + /** + * @group functional + */ public function testQuery() { $client = $this->_getClient(); @@ -15,14 +17,12 @@ class RangeTest extends BaseTest $index->create(array(), true); $type = $index->getType('test'); - $doc = new Document(1, array('age' => 16, 'height' => 140)); - $type->addDocument($doc); - $doc = new Document(2, array('age' => 21, 'height' => 155)); - $type->addDocument($doc); - $doc = new Document(3, array('age' => 33, 'height' => 160)); - $type->addDocument($doc); - $doc = new Document(4, array('age' => 68, 'height' => 160)); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1, array('age' => 16, 'height' => 140)), + new Document(2, array('age' => 21, 'height' => 155)), + new Document(3, array('age' => 33, 'height' => 160)), + new Document(4, array('age' => 68, 'height' => 160)), + )); $index->optimize(); $index->refresh(); @@ -38,6 +38,9 @@ class RangeTest extends BaseTest $this->assertEquals(2, $result); } + /** + * @group unit + */ public function testToArray() { $range = new Range(); @@ -48,12 +51,15 @@ class RangeTest extends BaseTest $expectedArray = array( 'range' => array( 'age' => $field, - ) + ), ); $this->assertEquals($expectedArray, $range->toArray()); } + /** + * @group unit + */ public function testConstruct() { $ranges = array('from' => 20, 'to' => 40); @@ -65,7 +71,7 @@ class RangeTest extends BaseTest $expectedArray = array( 'range' => array( 'age' => $ranges, - ) + ), ); $this->assertEquals($expectedArray, $range->toArray()); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RegexpTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RegexpTest.php new file mode 100644 index 00000000..c67e6317 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RegexpTest.php @@ -0,0 +1,31 @@ +<?php +namespace Elastica\Test\Query; + +use Elastica\Query\Regexp; +use Elastica\Test\Base as BaseTest; + +class RegexpTest extends BaseTest +{ + /** + * @group unit + */ + public function testToArray() + { + $field = 'name'; + $value = 'ruf'; + $boost = 2; + + $query = new Regexp($field, $value, $boost); + + $expectedArray = array( + 'regexp' => array( + $field => array( + 'value' => $value, + 'boost' => $boost, + ), + ), + ); + + $this->assertequals($expectedArray, $query->toArray()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RescoreTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RescoreTest.php index 4396ceb4..87842b0f 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RescoreTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RescoreTest.php @@ -1,27 +1,17 @@ <?php - namespace Elastica\Test\Query; -use Elastica\Rescore\Query as QueryRescore; -use Elastica\Query\Term; -use Elastica\Query\Match; use Elastica\Query; +use Elastica\Query\Match; +use Elastica\Query\Term; +use Elastica\Rescore\Query as QueryRescore; use Elastica\Test\Base as BaseTest; class RescoreTest extends BaseTest { /** - * @var Index + * @group unit */ - protected $_index; - - protected function setUp() - { - parent::setUp(); - $this->_index = $this->_createIndex("rescore_test"); - $this->_index->refresh(); - } - public function testToArray() { $query = new Query(); @@ -59,6 +49,9 @@ class RescoreTest extends BaseTest $this->assertEquals($expected, $data); } + /** + * @group unit + */ public function testSetSize() { $query = new Query(); @@ -98,6 +91,9 @@ class RescoreTest extends BaseTest $this->assertEquals($expected, $data); } + /** + * @group unit + */ public function testSetWeights() { $query = new Query(); @@ -133,7 +129,7 @@ class RescoreTest extends BaseTest ), ), 'query_weight' => 0.7, - 'rescore_query_weight' => 1.2 + 'rescore_query_weight' => 1.2, ), ), ); @@ -141,6 +137,79 @@ class RescoreTest extends BaseTest $this->assertEquals($expected, $data); } + /** + * @group functional + */ + public function testMultipleQueries() + { + $query = new Query(); + $mainQuery = new Match(); + $mainQuery = $mainQuery->setFieldQuery('test1', 'foo'); + + $secQuery1 = new Term(); + $secQuery1 = $secQuery1->setTerm('test2', 'bar', 1); + $rescoreQuery1 = new QueryRescore(); + $rescoreQuery1->setRescoreQuery($secQuery1); + + $secQuery2 = new Term(); + $secQuery2 = $secQuery2->setTerm('test2', 'tom', 2); + $rescoreQuery2 = new QueryRescore(); + $rescoreQuery2->setRescoreQuery($secQuery2); + + $query->setQuery($mainQuery); + $query->setRescore(array($rescoreQuery1, $rescoreQuery2)); + $data = $query->toArray(); + + $expected = array( + 'query' => array( + 'match' => array( + 'test1' => array( + 'query' => 'foo', + ), + ), + ), + 'rescore' => array( + array( + 'query' => array( + 'rescore_query' => array( + 'term' => array( + 'test2' => array( + 'value' => 'bar', + 'boost' => 1, + ), + ), + ), + ), + ), + array( + 'query' => array( + 'rescore_query' => array( + 'term' => array( + 'test2' => array( + 'value' => 'tom', + 'boost' => 2, + ), + ), + ), + ), + ), + ), + ); + + $this->assertEquals($expected, $data); + + $index = $this->_createIndex(); + $index->refresh(); + $results = $index->search($query); + $response = $results->getResponse(); + + $this->assertEquals(true, $response->isOk()); + $this->assertEquals(0, $results->getTotalHits()); + } + + /** + * @group functional + */ public function testQuery() { $query = new Query(); @@ -156,7 +225,9 @@ class RescoreTest extends BaseTest $query->setRescore($queryRescore); $data = $query->toArray(); - $results = $this->_index->search($query); + $index = $this->_createIndex(); + $index->refresh(); + $results = $index->search($query); $response = $results->getResponse(); $this->assertEquals(true, $response->isOk()); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php index eff9b8a1..80316547 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php @@ -1,73 +1,103 @@ <?php - namespace Elastica\Test\Query; - use Elastica\Document; -use Elastica\Index; use Elastica\Query\SimpleQueryString; use Elastica\Test\Base; class SimpleQueryStringTest extends Base { /** - * @var Index + * @group unit */ - protected $_index; + public function testToArray() + { + $string = 'this is a test'; + $fields = array('field1', 'field2'); + $query = new SimpleQueryString($string, $fields); + $query->setDefaultOperator(SimpleQueryString::OPERATOR_OR); + $query->setAnalyzer('whitespace'); + + $expected = array( + 'simple_query_string' => array( + 'query' => $string, + 'fields' => $fields, + 'analyzer' => 'whitespace', + 'default_operator' => SimpleQueryString::OPERATOR_OR, + ), + ); - protected function setUp() + $this->assertEquals($expected, $query->toArray()); + } + + /** + * @group functional + */ + public function testQuery() { - parent::setUp(); - $this->_index = $this->_createIndex("simple_query_string_test"); + $index = $this->_createIndex(); $docs = array( new Document(1, array('make' => 'Gibson', 'model' => 'Les Paul')), new Document(2, array('make' => 'Gibson', 'model' => 'SG Standard')), new Document(3, array('make' => 'Gibson', 'model' => 'SG Supreme')), new Document(4, array('make' => 'Gibson', 'model' => 'SG Faded')), - new Document(5, array('make' => 'Fender', 'model' => 'Stratocaster')) + new Document(5, array('make' => 'Fender', 'model' => 'Stratocaster')), ); - $this->_index->getType("guitars")->addDocuments($docs); - $this->_index->refresh(); - } + $index->getType('guitars')->addDocuments($docs); + $index->refresh(); - protected function tearDown() - { - parent::tearDown(); - $this->_index->delete(); + $query = new SimpleQueryString('gibson +sg +-faded', array('make', 'model')); + $results = $index->search($query); + + $this->assertEquals(2, $results->getTotalHits()); + + $query->setFields(array('model')); + $results = $index->search($query); + + // We should not get any hits, since the "make" field was not included in the query. + $this->assertEquals(0, $results->getTotalHits()); } - public function testToArray() + /** + * @group unit + */ + public function testSetMinimumShouldMatch() { - $string = "this is a test"; - $fields = array('field1', 'field2'); - $query = new SimpleQueryString($string, $fields); - $query->setDefaultOperator(SimpleQueryString::OPERATOR_OR); - $query->setAnalyzer("whitespace"); - $expected = array( - "simple_query_string" => array( - "query" => $string, - "fields" => $fields, - "analyzer" => "whitespace", - "default_operator" => SimpleQueryString::OPERATOR_OR - ) + 'simple_query_string' => array( + 'query' => 'DONT PANIC', + 'minimum_should_match' => '75%', + ), ); + $query = new SimpleQueryString($expected['simple_query_string']['query']); + $query->setMinimumShouldMatch($expected['simple_query_string']['minimum_should_match']); + $this->assertEquals($expected, $query->toArray()); + $this->assertInstanceOf('Elastica\Query\SimpleQueryString', $query->setMinimumShouldMatch('75%')); } - public function testQuery() + /** + * @group functional + */ + public function testSetMinimumShouldMatchWorks() { - $query = new SimpleQueryString("gibson +sg +-faded", array("make", "model")); - $results = $this->_index->search($query); + $index = $this->_createIndex(); + $type = $index->getType('foobars'); + $type->addDocuments(array( + new Document(1, array('body' => 'foo')), + new Document(2, array('body' => 'bar')), + new Document(3, array('body' => 'foo bar')), + new Document(4, array('body' => 'foo baz bar')), + )); + $index->refresh(); - $this->assertEquals(2, $results->getTotalHits()); - - $query->setFields(array("model")); - $results = $this->_index->search($query); + $query = new SimpleQueryString('foo bar'); + $query->setMinimumShouldMatch(2); + $results = $type->search($query); - // We should not get any hits, since the "make" field was not included in the query. - $this->assertEquals(0, $results->getTotalHits()); + $this->assertCount(2, $results); + $this->assertEquals(3, $results[0]->getId()); + $this->assertEquals(4, $results[1]->getId()); } } -
\ No newline at end of file diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleTest.php index 08a5f55d..b4f1dc8d 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Query\Simple; @@ -7,6 +6,9 @@ use Elastica\Test\Base as BaseTest; class SimpleTest extends BaseTest { + /** + * @group unit + */ public function testToArray() { $testQuery = array('hello' => array('world'), 'name' => 'ruflin'); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/TermTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/TermTest.php index 887c3849..da15f0f2 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/TermTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/TermTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Query\Term; @@ -7,7 +6,9 @@ use Elastica\Test\Base as BaseTest; class TermTest extends BaseTest { - + /** + * @group unit + */ public function testToArray() { $query = new Term(); diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/TermsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/TermsTest.php index 184f3ad6..f0c2b4b4 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/TermsTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/TermsTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; @@ -8,19 +7,19 @@ use Elastica\Test\Base as BaseTest; class TermsTest extends BaseTest { + /** + * @group functional + */ public function testFilteredSearch() { - $client = $this->_getClient(); - $index = $client->getIndex('test'); - $index->create(array(), true); + $index = $this->_createIndex(); $type = $index->getType('helloworld'); - $doc = new Document(1, array('name' => 'hello world')); - $type->addDocument($doc); - $doc = new Document(2, array('name' => 'nicolas ruflin')); - $type->addDocument($doc); - $doc = new Document(3, array('name' => 'ruflin')); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1, array('name' => 'hello world')), + new Document(2, array('name' => 'nicolas ruflin')), + new Document(3, array('name' => 'ruflin')), + )); $query = new Terms(); $query->setTerms('name', array('nicolas', 'hello')); @@ -37,6 +36,9 @@ class TermsTest extends BaseTest $this->assertEquals(3, $resultSet->count()); } + /** + * @group unit + */ public function testSetMinimum() { $key = 'name'; @@ -51,6 +53,7 @@ class TermsTest extends BaseTest } /** + * @group unit * @expectedException \Elastica\Exception\InvalidException */ public function testInvalidParams() diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/WildcardTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/WildcardTest.php index 077e6d4f..7a0c379e 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/WildcardTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/WildcardTest.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Test\Query; use Elastica\Document; @@ -9,12 +8,18 @@ use Elastica\Type\Mapping; class WildcardTest extends BaseTest { + /** + * @group unit + */ public function testConstructEmpty() { $wildcard = new Wildcard(); $this->assertEmpty($wildcard->getParams()); } + /** + * @group unit + */ public function testToArray() { $key = 'name'; @@ -27,14 +32,17 @@ class WildcardTest extends BaseTest 'wildcard' => array( $key => array( 'value' => $value, - 'boost' => $boost - ) - ) + 'boost' => $boost, + ), + ), ); $this->assertEquals($expectedArray, $wildcard->toArray()); } + /** + * @group functional + */ public function testSearchWithAnalyzer() { $client = $this->_getClient(); @@ -46,10 +54,10 @@ class WildcardTest extends BaseTest 'lw' => array( 'type' => 'custom', 'tokenizer' => 'keyword', - 'filter' => array('lowercase') - ) + 'filter' => array('lowercase'), + ), ), - ) + ), ); $index->create($indexParams, true); @@ -61,16 +69,13 @@ class WildcardTest extends BaseTest ); $type->setMapping($mapping); - $doc = new Document(1, array('name' => 'Basel-Stadt')); - $type->addDocument($doc); - $doc = new Document(2, array('name' => 'New York')); - $type->addDocument($doc); - $doc = new Document(3, array('name' => 'Baden')); - $type->addDocument($doc); - $doc = new Document(4, array('name' => 'Baden Baden')); - $type->addDocument($doc); - $doc = new Document(5, array('name' => 'New Orleans')); - $type->addDocument($doc); + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'Baden')), + new Document(4, array('name' => 'Baden Baden')), + new Document(5, array('name' => 'New Orleans')), + )); $index->refresh(); |