1
0
mirror of synced 2024-12-14 15:16:04 +03:00
This commit is contained in:
zYne 2007-07-26 23:44:18 +00:00
parent 0e8f67968c
commit 975d7ab044

View File

@ -57,17 +57,44 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$e->save(); $e->save();
} }
/**
public function testQuerySupportsSingleWordSearch() public function testQuerySupportsSingleWordSearch()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('doctrine'); $q->search('doctrine');
$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 = ? GROUP BY search_test_id ORDER BY relevance';
$this->assertEqual($q->getSql(), $sql); $this->assertEqual($q->getSql(), $sql);
} }
public function testSearchSupportsSingleTermWithQuotes()
{
$q = new Doctrine_Search_Query('SearchTestIndex');
$q->search("'doctrine orm'");
$sql = 'SELECT COUNT(keyword) AS relevance, 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);
}
public function testSearchSupportsSingleLongTermWithQuotes()
{
$q = new Doctrine_Search_Query('SearchTestIndex');
$q->search("'doctrine orm dbal'");
$sql = 'SELECT COUNT(keyword) AS relevance, search_test_id '
. 'FROM search_test_index WHERE keyword = ? '
. 'AND (position + 1) = (SELECT position FROM search_test_index WHERE keyword = ?) '
. 'AND (position + 2) = (SELECT position FROM search_test_index WHERE keyword = ?) '
. 'GROUP BY search_test_id ORDER BY relevance';
$this->assertEqual($q->getSql(), $sql);
}
public function testQuerySupportsMultiWordSearch() public function testQuerySupportsMultiWordSearch()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
@ -77,48 +104,53 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
. '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'; . 'GROUP BY search_test_id ORDER BY relevance';
$this->assertEqual($q->getSql(), $sql); $this->assertEqual($q->getSql(), $sql);
} }
public function testQuerySupportsMultiWordSearchWithWeights() public function testSearchSupportsMultipleTermsWithQuotes()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('doctrine^2 orm'); $q->search("doctrine 'orm database'");
$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'; . 'AND (position + 1) = (SELECT position FROM search_test_index WHERE keyword = ?)) '
. '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');
$q->search("doctrine^2 OR 'dbal database'"); $q->search("doctrine^2 OR 'dbal database'");
$sql = "SELECT foreign_id, SUM(relevancy) AS relevancy_sum FROM $sql = 'SELECT foreign_id, SUM(relevancy) AS relevancy_sum '
(SELECT COUNT(keyword) * 2 AS relevancy, foreign_id . 'FROM (SELECT COUNT(keyword) * 2 AS relevancy, foreign_id '
FROM search_index . 'FROM search_index '
WHERE keyword = 'doctrine' . 'WHERE keyword = ? '
GROUP BY foreign_id . 'GROUP BY foreign_id '
UNION . 'UNION '
SELECT COUNT(keyword) AS relevancy, foreign_id . 'SELECT COUNT(keyword) AS relevancy, foreign_id '
FROM search_index) AS query_alias . 'FROM search_index) AS query_alias '
WHERE keyword = 'dbal' AND (position + 1) = (SELECT position FROM search_index WHERE keyword = 'database') . 'WHERE keyword = ? AND (position + 1) = (SELECT position FROM search_index WHERE keyword = ?) '
GROUP BY foreign_id . 'GROUP BY foreign_id) '
GROUP BY foreign_id . 'GROUP BY foreign_id '
ORDER BY relevancy_sum"; . 'ORDER BY relevancy_sum';
print $q->getSql() . "<br>";
print $sql;
$this->assertEqual($q->getSql(), $sql);
} }
/**
public function testQuerySupportsMultiWordAndOperatorSearchWithQuotes() public function testQuerySupportsMultiWordAndOperatorSearchWithQuotes()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search("doctrine AND 'dbal database'"); $q->search("doctrine 'dbal database'");
$sql = "SELECT foreign_id, SUM(relevancy) AS relevancy_sum FROM $sql = "SELECT foreign_id, SUM(relevancy) AS relevancy_sum FROM
(SELECT COUNT(keyword) * 2 AS relevancy, foreign_id (SELECT COUNT(keyword) * 2 AS relevancy, foreign_id
@ -137,5 +169,15 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
AND (position + 1) = (SELECT position FROM search_index WHERE keyword = 'database') AND (position + 1) = (SELECT position FROM search_index WHERE keyword = 'database')
GROUP BY foreign_id GROUP BY foreign_id
ORDER BY relevancy_sum"; ORDER BY relevancy_sum";
$this->assertEqual($q->getSql(), $sql);
} }
public function testSearchReturnsFalseForEmptyStrings()
{
$q = new Doctrine_Search_Query('SearchTestIndex');
$result = $q->search(' ');
$this->assertFalse($result);
}
*/
} }