diff --git a/tests/Search/QueryTestCase.php b/tests/Search/QueryTestCase.php index 712ec43b1..7025dc84c 100644 --- a/tests/Search/QueryTestCase.php +++ b/tests/Search/QueryTestCase.php @@ -58,62 +58,13 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase $e->save(); } - public function testTokenizeClauseSupportsAndOperator() - { - $q = new Doctrine_Search_Query('SearchTestIndex'); - - $ret = $q->tokenizeClause('doctrine AND orm'); - - $this->assertEqual($ret, array(array('doctrine', 'orm'))); - } - - public function testTokenizeClauseSupportsOrOperator() - { - $q = new Doctrine_Search_Query('SearchTestIndex'); - - $ret = $q->tokenizeClause('doctrine OR orm'); - - $this->assertIdentical($ret, array('doctrine', 'orm')); - } - - public function testTokenizeClauseSupportsMixingOfOperators() - { - $q = new Doctrine_Search_Query('SearchTestIndex'); - - $ret = $q->tokenizeClause('doctrine OR orm OR dbal AND database OR rdbms'); - $expected = array('doctrine', 'orm', array('dbal', 'database'), 'rdbms'); - - $this->assertEqual($ret, $expected); - } - - public function testTokenizeClauseSupportsMixingOfOperatorsAndSpaces() - { - $q = new Doctrine_Search_Query('SearchTestIndex'); - - $ret = $q->tokenizeClause('doctrine OR orm dbal AND database OR rdbms'); - - $expected = array('doctrine', array('orm', 'dbal', 'database'), 'rdbms'); - - $this->assertEqual($ret, $expected); - } - - public function testTokenizeClauseSupportsMixingOfOperatorsAndParenthesis() - { - $q = new Doctrine_Search_Query('SearchTestIndex'); - - $ret = $q->tokenizeClause('doctrine OR orm OR (dbal AND database OR rdbms)'); - $expected = array('doctrine', 'orm', '(dbal and database or rdbms)'); - - $this->assertEqual($ret, $expected); - } - /* public function testParseClauseSupportsAndOperator() { $q = new Doctrine_Search_Query('SearchTestIndex'); $ret = $q->parseClause('doctrine AND orm'); - $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) ' - . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))'; + $sql = 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) ' + . 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)'; $this->assertEqual($ret, $sql); } @@ -123,9 +74,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase $q = new Doctrine_Search_Query('SearchTestIndex'); $ret = $q->parseClause('((doctrine OR orm) AND dbal) OR database'); - $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)) ' - . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))' - . ' OR keyword = ?'; + $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?) AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) OR keyword = ?'; $this->assertEqual($ret, $sql); } @@ -135,8 +84,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase $q = new Doctrine_Search_Query('SearchTestIndex'); $ret = $q->parseClause('doctrine OR orm AND dbal'); - $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)) ' - . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))'; + $sql = 'keyword = ? OR search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)'; $this->assertEqual($ret, $sql); } @@ -146,8 +94,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase $q = new Doctrine_Search_Query('SearchTestIndex'); $ret = $q->parseClause('(doctrine OR orm) AND dbal'); - $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)) ' - . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))'; + $sql = 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?) AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)'; $this->assertEqual($ret, $sql); } @@ -157,8 +104,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase $q = new Doctrine_Search_Query('SearchTestIndex'); $ret = $q->parseClause('(doctrine OR orm) dbal'); - $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)) ' - . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))'; + $sql = 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?) AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)'; $this->assertEqual($ret, $sql); } @@ -168,21 +114,27 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase $q = new Doctrine_Search_Query('SearchTestIndex'); $ret = $q->parseClause('(((doctrine OR orm) AND dbal) OR database) AND rdbms'); - $sql = '((search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)) ' - . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))' - . ' OR keyword = ?) AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))'; + $sql = '((search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?) AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) OR keyword = ?) AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)'; $this->assertEqual($ret, $sql); } + + public function testParseClauseSupportsMixingOfOperatorsAndParenthesis2() + { + $q = new Doctrine_Search_Query('SearchTestIndex'); + $ret = $q->parseClause('rdbms (dbal OR database)'); + + $sql = 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)'; + + $this->assertEqual($ret, $sql); + } + public function testParseClauseSupportsMixingOfOperatorsAndDeeplyNestedParenthesis2() { $q = new Doctrine_Search_Query('SearchTestIndex'); $ret = $q->parseClause('rdbms (((doctrine OR orm) AND dbal) OR database)'); - $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) AND ' - . '((search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)) ' - . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))' - . ' OR keyword = ?)'; + $sql = 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) AND ((search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?) AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) OR keyword = ?)'; $this->assertEqual($ret, $sql); } @@ -192,33 +144,36 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase $q = new Doctrine_Search_Query('SearchTestIndex'); $ret = $q->parseClause('rdbms -doctrine'); - $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) AND ' - . '(search_test_id NOT IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))'; + $sql = 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) AND ' + . 'search_test_id NOT IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)'; $this->assertEqual($ret, $sql); } + public function testParseClauseOrOperator2() { $q = new Doctrine_Search_Query('SearchTestIndex'); $ret = $q->parseClause('rdbms doctrine OR database'); - $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) AND ' - . '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) ' + $sql = 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) AND ' + . 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) ' . 'OR keyword = ?'; $this->assertEqual($ret, $sql); } + public function testParseClauseSupportsNegationOperatorWithOrOperator() { $q = new Doctrine_Search_Query('SearchTestIndex'); $ret = $q->parseClause('rdbms -doctrine OR database'); - $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) AND ' - . '(search_test_id NOT IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) ' + $sql = 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) AND ' + . 'search_test_id NOT IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) ' . 'OR keyword = ?'; $this->assertEqual($ret, $sql); } + public function testSearchSupportsAndOperator() { $q = new Doctrine_Search_Query('SearchTestIndex'); @@ -226,14 +181,14 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase $sql = 'SELECT COUNT(keyword) AS relevance, search_test_id ' . 'FROM search_test_index ' - . 'WHERE (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) ' - . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) ' + . 'WHERE search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) ' + . 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) ' . 'GROUP BY search_test_id ORDER BY relevance'; $this->assertEqual($q->getSql(), $sql); } - - /** + + public function testSearchSupportsOrOperator() { $q = new Doctrine_Search_Query('SearchTestIndex'); @@ -266,8 +221,8 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase $sql = 'SELECT COUNT(keyword) AS relevance, search_test_id ' . 'FROM search_test_index ' - . 'WHERE (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)) ' - . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) ' + . 'WHERE search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?) ' + . 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) ' . 'GROUP BY search_test_id ORDER BY relevance'; $this->assertEqual($q->getSql(), $sql); @@ -307,8 +262,8 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase $sql = 'SELECT COUNT(keyword) AS relevance, search_test_id ' . 'FROM search_test_index ' - . 'WHERE (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) ' - . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) ' + . 'WHERE search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) ' + . 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) ' . 'GROUP BY search_test_id ORDER BY relevance'; $this->assertEqual($q->getSql(), $sql); @@ -321,9 +276,9 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase $sql = 'SELECT COUNT(keyword) AS relevance, search_test_id ' . 'FROM search_test_index ' - . 'WHERE (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) ' - . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? ' - . 'AND (position + 1) = (SELECT position FROM search_test_index WHERE keyword = ?))) ' + . 'WHERE search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) ' + . 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? ' + . 'AND (position + 1) = (SELECT position FROM search_test_index WHERE keyword = ?)) ' . 'GROUP BY search_test_id ORDER BY relevance'; $this->assertEqual($q->getSql(), $sql);