From 15e69f7b20b6596b9148030acce5b59993b95a45 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 18 Dec 2015 06:00:00 +0100 Subject: Update to MediaWiki 1.25.4 --- .../lib/Elastica/Test/Query/ConstantScoreTest.php | 158 +++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php') diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php new file mode 100644 index 00000000..27143eb6 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php @@ -0,0 +1,158 @@ + array( + 'filter' => array( + 'term' => array( + 'foo', + 'bar', + ), + ), + ), + ), + ), + array( + array( + 'and' => array( + array( + 'query' => array( + 'query_string' => array( + 'query' => 'foo', + 'default_field' => 'something', + ), + ), + ), + array( + 'query' => array( + 'query_string' => array( + 'query' => 'bar', + 'default_field' => 'something', + ), + ), + ), + ), + ), + '{"constant_score":{"filter":{"and":[{"query":{"query_string":{"query":"foo","default_field":"something"}}},{"query":{"query_string":{"query":"bar","default_field":"something"}}}]}}}', + ), + ); + } + /** + * @dataProvider dataProviderSampleQueries + */ + public function testSimple($filter, $expected) + { + $query = new ConstantScore(); + $query->setFilter($filter); + if (is_string($expected)) { + $expected = json_decode($expected, true); + } + $this->assertEquals($expected, $query->toArray()); + } + + public function testToArray() + { + $query = new ConstantScore(); + + $boost = 1.2; + $filter = new Ids(); + $filter->setIds(array(1)); + + $query->setFilter($filter); + $query->setBoost($boost); + + $expectedArray = array( + 'constant_score' => array( + 'filter' => $filter->toArray(), + 'boost' => $boost + ) + ); + + $this->assertEquals($expectedArray, $query->toArray()); + } + + public function testConstruct() + { + $filter = new Ids(); + $filter->setIds(array(1)); + + $query = new ConstantScore($filter); + + $expectedArray = array( + 'constant_score' => array( + 'filter' => $filter->toArray(), + ) + ); + + $this->assertEquals($expectedArray, $query->toArray()); + + } + + public function testQuery() + { + + $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); + + // Refresh index + $index->refresh(); + + $boost = 1.3; + $query_match = new MatchAll(); + + $query = new ConstantScore(); + $query->setQuery($query_match); + $query->setBoost($boost); + + $expectedArray = array( + 'constant_score' => array( + 'query' => $query_match->toArray(), + 'boost' => $boost + ) + ); + + $this->assertEquals($expectedArray, $query->toArray()); + $resultSet = $type->search($query); + + $results = $resultSet->getResults(); + + $this->assertEquals($resultSet->count(), 3); + $this->assertEquals($results[1]->getScore(), 1); + + } + + public function testConstructEmpty() + { + $query = new ConstantScore(); + $expectedArray = array('constant_score' => array()); + + $this->assertEquals($expectedArray, $query->toArray()); + } +} -- cgit v1.2.2