Commit 2b32cc07 authored by zYne's avatar zYne

--no commit message

--no commit message
parent f81c5c3b
...@@ -58,62 +58,13 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -58,62 +58,13 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$e->save(); $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() public function testParseClauseSupportsAndOperator()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('doctrine AND orm'); $ret = $q->parseClause('doctrine AND orm');
$sql = '(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 = ?))'; . 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)';
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
...@@ -123,9 +74,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -123,9 +74,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('((doctrine OR orm) AND dbal) OR database'); $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 = ?)) ' $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 = ?))'
. ' OR keyword = ?';
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
...@@ -135,8 +84,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -135,8 +84,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('doctrine OR orm AND dbal'); $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 = ?)) ' $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 = ?)';
. 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))';
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
...@@ -146,8 +94,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -146,8 +94,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('(doctrine OR orm) AND dbal'); $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 = ?)) ' $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 = ?)';
. 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))';
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
...@@ -157,8 +104,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -157,8 +104,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('(doctrine OR orm) dbal'); $ret = $q->parseClause('(doctrine OR orm) dbal');
$sql = '(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 = ?)';
. 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))';
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
...@@ -168,21 +114,27 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -168,21 +114,27 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('(((doctrine OR orm) AND dbal) OR database) AND rdbms'); $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 = ?)) ' $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 = ?)';
. '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); $this->assertEqual($ret, $sql);
} }
public function testParseClauseSupportsMixingOfOperatorsAndDeeplyNestedParenthesis2() public function testParseClauseSupportsMixingOfOperatorsAndDeeplyNestedParenthesis2()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('rdbms (((doctrine OR orm) AND dbal) OR database)'); $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 ' $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 = ?)';
. '((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); $this->assertEqual($ret, $sql);
} }
...@@ -192,33 +144,36 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -192,33 +144,36 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('rdbms -doctrine'); $ret = $q->parseClause('rdbms -doctrine');
$sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) AND ' $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 = ?))'; . 'search_test_id NOT IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)';
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
public function testParseClauseOrOperator2() public function testParseClauseOrOperator2()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('rdbms doctrine OR database'); $ret = $q->parseClause('rdbms doctrine OR database');
$sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) AND ' $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 = ?)) ' . 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) '
. 'OR keyword = ?'; . 'OR keyword = ?';
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
public function testParseClauseSupportsNegationOperatorWithOrOperator() public function testParseClauseSupportsNegationOperatorWithOrOperator()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('rdbms -doctrine OR database'); $ret = $q->parseClause('rdbms -doctrine OR database');
$sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) AND ' $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 = ?)) ' . 'search_test_id NOT IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) '
. 'OR keyword = ?'; . 'OR keyword = ?';
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
public function testSearchSupportsAndOperator() public function testSearchSupportsAndOperator()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
...@@ -226,14 +181,14 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -226,14 +181,14 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$sql = 'SELECT COUNT(keyword) AS relevance, search_test_id ' $sql = 'SELECT COUNT(keyword) AS relevance, search_test_id '
. 'FROM search_test_index ' . 'FROM search_test_index '
. 'WHERE (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 = ?)) ' . 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) '
. 'GROUP BY search_test_id ORDER BY relevance'; . 'GROUP BY search_test_id ORDER BY relevance';
$this->assertEqual($q->getSql(), $sql); $this->assertEqual($q->getSql(), $sql);
} }
/**
public function testSearchSupportsOrOperator() public function testSearchSupportsOrOperator()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
...@@ -266,8 +221,8 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -266,8 +221,8 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$sql = 'SELECT COUNT(keyword) AS relevance, search_test_id ' $sql = 'SELECT COUNT(keyword) AS relevance, search_test_id '
. 'FROM search_test_index ' . 'FROM search_test_index '
. 'WHERE (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR 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 = ?)) ' . 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) '
. 'GROUP BY search_test_id ORDER BY relevance'; . 'GROUP BY search_test_id ORDER BY relevance';
$this->assertEqual($q->getSql(), $sql); $this->assertEqual($q->getSql(), $sql);
...@@ -307,8 +262,8 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -307,8 +262,8 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$sql = 'SELECT COUNT(keyword) AS relevance, search_test_id ' $sql = 'SELECT COUNT(keyword) AS relevance, search_test_id '
. 'FROM search_test_index ' . 'FROM search_test_index '
. 'WHERE (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 = ?)) ' . 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) '
. 'GROUP BY search_test_id ORDER BY relevance'; . 'GROUP BY search_test_id ORDER BY relevance';
$this->assertEqual($q->getSql(), $sql); $this->assertEqual($q->getSql(), $sql);
...@@ -321,9 +276,9 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -321,9 +276,9 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$sql = 'SELECT COUNT(keyword) AS relevance, search_test_id ' $sql = 'SELECT COUNT(keyword) AS relevance, search_test_id '
. 'FROM search_test_index ' . 'FROM search_test_index '
. 'WHERE (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 = ? ' . '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 = ?))) ' . 'AND (position + 1) = (SELECT position FROM search_test_index WHERE keyword = ?)) '
. 'GROUP BY search_test_id ORDER BY relevance'; . 'GROUP BY search_test_id ORDER BY relevance';
$this->assertEqual($q->getSql(), $sql); $this->assertEqual($q->getSql(), $sql);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment