1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00
This commit is contained in:
zYne 2007-07-30 19:01:59 +00:00
parent 7ab2e58609
commit 5866a6f78f

View file

@ -57,7 +57,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$e->save(); $e->save();
} }
/*'
public function testTokenizeClauseSupportsAndOperator() public function testTokenizeClauseSupportsAndOperator()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
@ -186,7 +186,39 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
/** */
public function testParseClauseSupportsNegationOperator()
{
$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 = ?))';
$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 = ?)) '
. '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 = ?)) '
. 'OR keyword = ?';
$this->assertEqual($ret, $sql);
}
public function testSearchSupportsAndOperator() public function testSearchSupportsAndOperator()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
@ -194,12 +226,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');
@ -212,19 +246,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getSql(), $sql); $this->assertEqual($q->getSql(), $sql);
} }
public function testSearchSupportsMixingOfOperators()
{
$q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('(doctrine OR orm) AND dbal');
$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 = ?) '
. 'GROUP BY search_test_id ORDER BY relevance';
$this->assertEqual($q->getSql(), $sql);
}
public function testQuerySupportsSingleWordSearch() public function testQuerySupportsSingleWordSearch()
{ {
@ -236,12 +258,26 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getSql(), $sql); $this->assertEqual($q->getSql(), $sql);
} }
*/
public function testSearchSupportsMixingOfOperators()
{
$q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('(doctrine OR orm) AND dbal');
$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 = ?)) '
. 'GROUP BY search_test_id ORDER BY relevance';
$this->assertEqual($q->getSql(), $sql);
}
public function testSearchSupportsSingleTermWithQuotes() public function testSearchSupportsSingleTermWithQuotes()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search("'doctrine orm'"); $q->search("'doctrine orm'");
$sql = 'SELECT COUNT(keyword) AS relevance, search_test_id ' $sql = 'SELECT COUNT(keyword) AS relevance, search_test_id '
. 'FROM search_test_index WHERE keyword = ? ' . '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 = ?) '
@ -249,11 +285,12 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getSql(), $sql); $this->assertEqual($q->getSql(), $sql);
} }
public function testSearchSupportsSingleLongTermWithQuotes() public function testSearchSupportsSingleLongTermWithQuotes()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search("'doctrine orm dbal'"); $q->search("'doctrine orm dbal'");
$sql = 'SELECT COUNT(keyword) AS relevance, search_test_id ' $sql = 'SELECT COUNT(keyword) AS relevance, search_test_id '
. 'FROM search_test_index WHERE keyword = ? ' . '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 = ?) '
@ -270,8 +307,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);
@ -284,14 +321,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 = ? '
. '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);
} }
/**
public function testQuerySupportsMultiWordOrOperatorSearchWithQuotes() public function testQuerySupportsMultiWordOrOperatorSearchWithQuotes()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
@ -314,7 +351,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
print $sql; print $sql;
$this->assertEqual($q->getSql(), $sql); $this->assertEqual($q->getSql(), $sql);
} }
*/ /**
public function testQuerySupportsMultiWordAndOperatorSearchWithQuotes() public function testQuerySupportsMultiWordAndOperatorSearchWithQuotes()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');