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 --- .../lib/Elastica/Test/Query/MultiMatchTest.php | 187 +++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MultiMatchTest.php (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MultiMatchTest.php') diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MultiMatchTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MultiMatchTest.php new file mode 100644 index 00000000..78a8a8fe --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/MultiMatchTest.php @@ -0,0 +1,187 @@ + 1, 'name' => 'Rodolfo', 'last_name' => 'Moraes', 'full_name' => 'Rodolfo Moraes'), + array('id' => 2, 'name' => 'Tristan', 'last_name' => 'Maindron', 'full_name' => 'Tristan Maindron'), + array('id' => 3, 'name' => 'Monique', 'last_name' => 'Maindron', 'full_name' => 'Monique Maindron'), + 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(); + } + + public function testMinimumShouldMatch() + { + $this->multiMatch->setQuery('Tristan Maindron'); + $this->multiMatch->setFields(array('full_name', 'name')); + $this->multiMatch->setMinimumShouldMatch(2); + $resultSet = $this->_getResults(); + + $this->assertEquals(1, $resultSet->count()); + } + + public function testAndOperator() + { + $this->multiMatch->setQuery('Monique Maindron'); + $this->multiMatch->setFields(array('full_name', 'name')); + $this->multiMatch->setOperator(MultiMatch::OPERATOR_AND); + $resultSet = $this->_getResults(); + + $this->assertEquals(1, $resultSet->count()); + } + + public function testType() + { + $this->multiMatch->setQuery('Trist'); + $this->multiMatch->setFields(array('full_name', 'name')); + $this->multiMatch->setType(MultiMatch::TYPE_PHRASE_PREFIX); + $resultSet = $this->_getResults(); + + $this->assertEquals(1, $resultSet->count()); + } + + public function testFuzzy() + { + $this->multiMatch->setQuery('Tritsan'); // Mispell on purpose + $this->multiMatch->setFields(array('full_name', 'name')); + $this->multiMatch->setFuzziness(2); + $resultSet = $this->_getResults(); + + $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(); + + $this->assertEquals(0, $resultSet->count()); + } + + 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(); + + $this->assertEquals(0, $resultSet->count()); + } + + 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(); + + $this->assertEquals(1, $resultSet->count()); + } + + 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(); + + $this->assertEquals(0, $resultSet->count()); + + $this->multiMatch->setZeroTermsQuery(MultiMatch::ZERO_TERM_ALL); + $resultSet = $this->_getResults(); + + $this->assertEquals(4, $resultSet->count()); + } + + public function testBaseMultiMatch() + { + $this->multiMatch->setQuery('Rodolfo'); + $this->multiMatch->setFields(array('name', 'last_name')); + $resultSet = $this->_getResults(); + + $this->assertEquals(1, $resultSet->count()); + + $this->multiMatch->setQuery('Moraes'); + $this->multiMatch->setFields(array('name', 'last_name')); + $resultSet = $this->_getResults(); + + $this->assertEquals(1, $resultSet->count()); + } + + /** + * Executes the query with the current multimatch. + */ + private function _getResults() + { + return $this->index->search(new Query($this->multiMatch)); + } + + /** + * Builds an index for testing. + */ + private function _generateIndex() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + + $index->create(array( + 'analysis' => array( + 'analyzer' => array( + 'noStops' => array( + 'type' => 'standard', + 'stopwords' => '_none_' + ), + 'stops' => array( + 'type' => 'standard', + 'stopwords' => array('not') + ), + ), + ) + ), true); + + $type = $index->getType('test'); + + $mapping = new Mapping($type, array( + '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'), + )); + + $type->setMapping($mapping); + + foreach (self::$data as $key => $docData) { + $type->addDocument(new Document($key, $docData)); + } + + // Refresh index + $index->refresh(); + + return $index; + } +} -- cgit v1.2.3-54-g00ecf