From a1789ddde42033f1b05cc4929491214ee6e79383 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 17 Dec 2015 09:15:42 +0100 Subject: Update to MediaWiki 1.26.0 --- .../lib/Elastica/Test/Facet/DateHistogramTest.php | 106 +++++++++++++++++++ .../test/lib/Elastica/Test/Facet/FilterTest.php | 42 ++++++++ .../lib/Elastica/Test/Facet/GeoClusterTest.php | 57 +++++++++++ .../test/lib/Elastica/Test/Facet/QueryTest.php | 42 ++++++++ .../lib/Elastica/Test/Facet/StatisticalTest.php | 82 +++++++++++++++ .../lib/Elastica/Test/Facet/TermsStatsTest.php | 113 +++++++++++++++++++++ .../test/lib/Elastica/Test/Facet/TermsTest.php | 74 ++++++++++++++ 7 files changed, 516 insertions(+) create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/DateHistogramTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/FilterTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/GeoClusterTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/QueryTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/StatisticalTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsStatsTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsTest.php (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Facet') diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/DateHistogramTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/DateHistogramTest.php new file mode 100644 index 00000000..96d30aa2 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/DateHistogramTest.php @@ -0,0 +1,106 @@ +assertInstanceOf('Elastica\Facet\Histogram', $facet); + $this->assertInstanceOf('Elastica\Facet\AbstractFacet', $facet); + unset($facet); + } + + /** + * @group functional + */ + public function testQuery() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $mapping = new Mapping($type, array( + 'name' => array('type' => 'string', 'store' => 'no'), + 'dtmPosted' => array('type' => 'date', 'store' => 'no', 'format' => 'yyyy-MM-dd HH:mm:ss'), + )); + $type->setMapping($mapping); + + $doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => '2011-06-23 21:53:00')); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => '2011-06-23 09:53:00')); + $type->addDocument($doc); + $doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => '2011-07-08 08:53:00')); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => '2011-07-08 01:53:00')); + $type->addDocument($doc); + + $facet = new DateHistogram('dateHist1'); + $facet->setInterval('day'); + $facet->setField('dtmPosted'); + + $query = new Query(); + $query->addFacet($facet); + $query->setQuery(new MatchAll()); + $index->refresh(); + + $response = $type->search($query); + $facets = $response->getFacets(); + + $this->assertEquals(4, $response->getTotalHits()); + $this->assertEquals(2, count($facets['dateHist1']['entries'])); + } + + /** + * @group functional + */ + public function testFactor() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $mapping = new Mapping($type, array( + 'name' => array('type' => 'string', 'store' => 'no'), + 'dtmPosted' => array('type' => 'long', 'store' => 'no'), + )); + $type->setMapping($mapping); + + $doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => 1308865980)); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => 1308822780)); + $type->addDocument($doc); + $doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => 1310115180)); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => 1310089980)); + $type->addDocument($doc); + + $facet = new DateHistogram('dateHist1'); + $facet->setInterval('day'); + $facet->setField('dtmPosted'); + $facet->setFactor(1000); + + $query = new Query(); + $query->addFacet($facet); + $query->setQuery(new MatchAll()); + $index->refresh(); + + $response = $type->search($query); + $facets = $response->getFacets(); + + $this->assertEquals(4, $response->getTotalHits()); + $this->assertEquals(2, count($facets['dateHist1']['entries'])); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/FilterTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/FilterTest.php new file mode 100644 index 00000000..622923fe --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/FilterTest.php @@ -0,0 +1,42 @@ +_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $type->addDocument(new Document(1, array('color' => 'red'))); + $type->addDocument(new Document(2, array('color' => 'green'))); + $type->addDocument(new Document(3, array('color' => 'blue'))); + + $index->refresh(); + + $filter = new Term(array('color' => 'red')); + + $facet = new Filter('test'); + $facet->setFilter($filter); + + $query = new Query(); + $query->addFacet($facet); + + $resultSet = $type->search($query); + + $facets = $resultSet->getFacets(); + + $this->assertEquals(1, $facets['test']['count']); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/GeoClusterTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/GeoClusterTest.php new file mode 100644 index 00000000..f771ac32 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/GeoClusterTest.php @@ -0,0 +1,57 @@ +_getClient(); + $nodes = $client->getCluster()->getNodes(); + if (!$nodes[0]->getInfo()->hasPlugin('geocluster-facet')) { + $this->markTestSkipped('geocluster-facet plugin not installed'); + } + + $index = $this->_createIndex(); + $type = $index->getType('testQuery'); + $geoField = 'location'; + + $type->setMapping(new Mapping($type, array( + $geoField => array('type' => 'geo_point', 'lat_lon' => true), + ))); + + $doc = new Document(1, array('name' => 'item1', 'location' => array(20, 20))); + $type->addDocument($doc); + + $doc = new Document(2, array('name' => 'item2', 'location' => array(20, 20))); + $type->addDocument($doc); + + $doc = new Document(3, array('name' => 'item3', 'location' => array(20, 20))); + $type->addDocument($doc); + + $index->refresh(); + + $facet = new GeoCluster('clusters'); + $facet + ->setField($geoField) + ->setFactor(1) + ->setShowIds(false); + $query = new Query(); + $query->setFacets(array($facet)); + + $response = $type->search($query); + $facets = $response->getFacets(); + + $this->assertEquals(1, count($facets['clusters']['clusters'])); + + $index->delete(); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/QueryTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/QueryTest.php new file mode 100644 index 00000000..8e0231aa --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/QueryTest.php @@ -0,0 +1,42 @@ +_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $type->addDocument(new Document(1, array('color' => 'red'))); + $type->addDocument(new Document(2, array('color' => 'green'))); + $type->addDocument(new Document(3, array('color' => 'blue'))); + + $index->refresh(); + + $termQuery = new Term(array('color' => 'red')); + + $facet = new FacetQuery('test'); + $facet->setQuery($termQuery); + + $query = new Query(); + $query->addFacet($facet); + + $resultSet = $type->search($query); + + $facets = $resultSet->getFacets(); + + $this->assertEquals(1, $facets['test']['count']); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/StatisticalTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/StatisticalTest.php new file mode 100644 index 00000000..dc374289 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/StatisticalTest.php @@ -0,0 +1,82 @@ +_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $doc = new Document(1, array('price' => 10)); + $type->addDocument($doc); + $doc = new Document(2, array('price' => 35)); + $type->addDocument($doc); + $doc = new Document(2, array('price' => 45)); + $type->addDocument($doc); + + $facet = new Statistical('stats'); + $facet->setField('price'); + + $query = new Query(); + $query->addFacet($facet); + $query->setQuery(new MatchAll()); + + $index->refresh(); + + $response = $type->search($query); + $facets = $response->getFacets(); + + $this->assertEquals(55, $facets['stats']['total']); + $this->assertEquals(10, $facets['stats']['min']); + $this->assertEquals(45, $facets['stats']['max']); + } + + /** + * @group functional + */ + public function testStatisticalWithSetFields() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $doc = new Document(1, array('price' => 10, 'price2' => 20)); + $type->addDocument($doc); + $doc = new Document(2, array('price' => 35, 'price2' => 70)); + $type->addDocument($doc); + $doc = new Document(2, array('price' => 45, 'price2' => 90)); + $type->addDocument($doc); + + $facet = new Statistical('stats'); + $facet->setFields(array('price', 'price2')); + + $query = new Query(); + $query->addFacet($facet); + $query->setQuery(new MatchAll()); + + $index->refresh(); + + $response = $type->search($query); + $facets = $response->getFacets(); + + $this->assertEquals(165, $facets['stats']['total']); + $this->assertEquals(10, $facets['stats']['min']); + $this->assertEquals(90, $facets['stats']['max']); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsStatsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsStatsTest.php new file mode 100644 index 00000000..e3377930 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsStatsTest.php @@ -0,0 +1,113 @@ +_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $doc = new Document(1, array('name' => 'tom', 'paid' => 7)); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'tom', 'paid' => 2)); + $type->addDocument($doc); + $doc = new Document(3, array('name' => 'tom', 'paid' => 5)); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'mike', 'paid' => 13)); + $type->addDocument($doc); + $doc = new Document(5, array('name' => 'mike', 'paid' => 1)); + $type->addDocument($doc); + $doc = new Document(6, array('name' => 'mike', 'paid' => 15)); + $type->addDocument($doc); + + $facet = new TermsStats('test'); + $facet->setKeyField('name'); + $facet->setValueField('paid'); + $facet->setOrder('reverse_total'); + + $query = new Query(); + $query->addFacet($facet); + $query->setQuery(new MatchAll()); + + $index->refresh(); + + $response = $type->search($query); + $facets = $response->getFacets(); + + $this->assertEquals(14, $facets[ 'test' ][ 'terms' ][0]['total']); + $this->assertEquals(29, $facets[ 'test' ][ 'terms' ][1]['total']); + } + + /** + * @group functional + */ + public function testQuery() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $doc = new Document(1, array('name' => 'tom', 'paid' => 7)); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'tom', 'paid' => 2)); + $type->addDocument($doc); + $doc = new Document(3, array('name' => 'tom', 'paid' => 5)); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'mike', 'paid' => 13)); + $type->addDocument($doc); + $doc = new Document(5, array('name' => 'mike', 'paid' => 1)); + $type->addDocument($doc); + $doc = new Document(6, array('name' => 'mike', 'paid' => 15)); + $type->addDocument($doc); + + $facet = new TermsStats('test'); + $facet->setKeyField('name'); + $facet->setValueField('paid'); + + $query = new Query(); + $query->addFacet($facet); + $query->setQuery(new MatchAll()); + + $index->refresh(); + + $response = $type->search($query); + $facets = $response->getFacets(); + + $this->assertEquals(2, count($facets[ 'test' ][ 'terms' ])); + foreach ($facets[ 'test' ][ 'terms' ] as $facet) { + if ($facet[ 'term' ] === 'tom') { + $this->assertEquals(14, $facet[ 'total' ]); + } + if ($facet[ 'term' ] === 'mike') { + $this->assertEquals(29, $facet[ 'total' ]); + } + } + } + + /** + * @group unit + */ + public function testSetSize() + { + $facet = new TermsStats('test'); + $facet->setSize(100); + + $data = $facet->toArray(); + + $this->assertArrayHasKey('size', $data['terms_stats']); + $this->assertEquals(100, $data['terms_stats']['size']); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsTest.php new file mode 100644 index 00000000..f4c95796 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/TermsTest.php @@ -0,0 +1,74 @@ +_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $doc = new Document(1, array('name' => 'nicolas ruflin')); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'ruflin test')); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'nicolas helloworld')); + $type->addDocument($doc); + + $facet = new Terms('test'); + $facet->setField('name'); + + $query = new Query(); + $query->addFacet($facet); + $query->setQuery(new MatchAll()); + + $index->refresh(); + + $response = $type->search($query); + $facets = $response->getFacets(); + + $this->assertEquals(3, count($facets['test']['terms'])); + } + + /** + * @group functional + */ + public function testFacetScript() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('helloworld'); + + $doc = new Document(1, array('name' => 'rodolfo', 'last_name' => 'moraes')); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'jose', 'last_name' => 'honjoya')); + $type->addDocument($doc); + + $facet = new Terms('test'); + $facet->setField('name'); + $facet->setScript('term + " "+doc["last_name"].value'); + + $query = new Query(); + $query->addFacet($facet); + $query->setQuery(new MatchAll()); + + $index->refresh(); + + $response = $type->search($query); + $facets = $response->getFacets(); + + $this->assertEquals(2, count($facets['test']['terms'])); + } +} -- cgit v1.2.3-54-g00ecf