From 1a365e77dfb8825136626202b1df462731b42060 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 16 Aug 2015 08:22:05 +0200 Subject: Update to MediaWiki 1.25.2 --- .../test/lib/Elastica/Test/Query/MatchTest.php | 187 +++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchTest.php (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchTest.php') diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchTest.php new file mode 100644 index 00000000..ed164663 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MatchTest.php @@ -0,0 +1,187 @@ +setFieldQuery($field, $testQuery); + $query->setFieldType($field, $type); + $query->setFieldOperator($field, $operator); + $query->setFieldAnalyzer($field, $analyzer); + $query->setFieldBoost($field, $boost); + $query->setFieldMinimumShouldMatch($field, $minimumShouldMatch); + $query->setFieldFuzziness($field, $fuzziness); + $query->setFieldFuzzyRewrite($field, $fuzzyRewrite); + $query->setFieldPrefixLength($field, $prefixLength); + $query->setFieldMaxExpansions($field, $maxExpansions); + + $expectedArray = array( + 'match' => array( + $field => array( + 'query' => $testQuery, + 'type' => $type, + 'operator' => $operator, + 'analyzer' => $analyzer, + 'boost' => $boost, + 'minimum_should_match' => $minimumShouldMatch, + 'fuzziness' => $fuzziness, + 'fuzzy_rewrite' => $fuzzyRewrite, + 'prefix_length' => $prefixLength, + 'max_expansions' => $maxExpansions + ) + ) + ); + + $this->assertEquals($expectedArray, $query->toArray()); + } + + public function testMatch() + { + $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); + $doc = new Document(3, array('name' => 'New Hampshire')); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'Basel Land')); + $type->addDocument($doc); + + $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()); + } + + 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); + $index->refresh(); + + $query = new Match(); + $query->setFieldQuery('name', ''); + $query->setFieldZeroTermsQuery('name', Match::ZERO_TERM_ALL); + + $resultSet = $index->search($query); + + $this->assertEquals(2, $resultSet->count()); + } + + public function testMatchPhrase() + { + $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); + $doc = new Document(3, array('name' => 'New Hampshire')); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'Basel Land')); + $type->addDocument($doc); + + $index->refresh(); + + $field = 'name'; + $type = 'phrase'; + + $query = new Match(); + $query->setFieldQuery($field, 'New York'); + $query->setFieldType($field, $type); + + $resultSet = $index->search($query); + + $this->assertEquals(1, $resultSet->count()); + } + + public function testMatchPhrasePrefix() + { + $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); + $doc = new Document(3, array('name' => 'New Hampshire')); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'Basel Land')); + $type->addDocument($doc); + + $index->refresh(); + + $field = 'name'; + $type = 'phrase_prefix'; + + $query = new Match(); + $query->setFieldQuery($field, 'New'); + $query->setFieldType($field, $type); + + $resultSet = $index->search($query); + + $this->assertEquals(2, $resultSet->count()); + } + + + public function testMatchFuzzinessType() + { + $field = 'test'; + $query = new Match(); + + $fuzziness = "AUTO"; + $query->setFieldFuzziness($field, $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']); + } +} -- cgit v1.2.3