1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00
This commit is contained in:
zYne 2007-07-26 19:06:42 +00:00
parent 7c7645f801
commit 975069e025

View file

@ -57,68 +57,85 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$e->save(); $e->save();
} }
public function testQuerySupportsSingleWordSearch()
public function testQuerying()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->select('s.*') $q->search('doctrine');
->from('SearchTest s');
$sql = 'SELECT COUNT(keyword) AS relevance, search_test_id '
. 'FROM search_test_index WHERE keyword = ?';
$this->assertEqual($q->getSql(), $sql);
}
public function testQuerySupportsMultiWordSearch()
{
$q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('doctrine orm');
$sq = new Doctrine_Search_Query($q); $sql = 'SELECT COUNT(keyword) AS relevance, search_test_id '
$sq->addAlias('i'); . 'FROM search_test_index '
$sq->search('ORM framework'); . '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';
//print $q->getDql(); $this->assertEqual($q->getSql(), $sql);
//$coll = $sq->execute(); }
public function testQuerySupportsMultiWordSearchWithWeights()
{
$q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('doctrine^2 orm');
$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 = ?) '
. 'GROUP BY search_test_id';
$this->assertEqual($q->getSql(), $sql);
//$this->assertEqual($coll[0]->relevancy, 2);
//$this->assertEqual($coll[1]->relevancy, 0);
} }
public function testGettingRelevancyValues() public function testQuerySupportsMultiWordOrOperatorSearchWithQuotes()
{ {
$dql = 'SELECT s.*, $q = new Doctrine_Search_Query('SearchTestIndex');
(SELECT COUNT(o.position) $q->search("doctrine^2 OR 'dbal database'");
FROM SearchTestIndex o
WHERE o.keyword = ?
AND s.id = o.searchtest_id) relevancy
FROM SearchTest s LEFT JOIN s.SearchTestIndex i2
WHERE i2.keyword = ?';
$q = new Doctrine_Query(); $sql = "SELECT foreign_id, SUM(relevancy) AS relevancy_sum FROM
(SELECT COUNT(keyword) * 2 AS relevancy, foreign_id
$q->parseQuery($dql); FROM search_index
$coll = $q->execute(array('orm', 'orm'), Doctrine_Hydrate::HYDRATE_ARRAY); WHERE keyword = 'doctrine'
//print_r($coll); GROUP BY foreign_id
//$this->assertEqual($coll[0]->relevancy, 2); UNION
//$this->assertEqual($coll[1]->relevancy, 0); SELECT COUNT(keyword) AS relevancy, foreign_id
FROM search_index) AS query_alias
WHERE keyword = 'dbal' AND (position + 1) = (SELECT position FROM search_index WHERE keyword = 'database')
GROUP BY foreign_id
GROUP BY foreign_id
ORDER BY relevancy_sum";
} }
/**
public function testGettingWeightedRelevancyValues() public function testQuerySupportsMultiWordAndOperatorSearchWithQuotes()
{ {
$dql = "SELECT s.*, $q = new Doctrine_Search_Query('SearchTestIndex');
((SELECT COUNT(i.id) $q->search("doctrine AND 'dbal database'");
FROM SearchTestIndex i
WHERE i.keyword = ?
AND i.searchtest_id = s.id
AND i.field = 'title') * 2
+
(SELECT COUNT(i.id)
FROM SearchTestIndex i
WHERE i.keyword = ?
AND i.searchtest_id = s.id
AND i.field = 'content')) relevancy
FROM SearchTest s";
$q = new Doctrine_Query(); $sql = "SELECT foreign_id, SUM(relevancy) AS relevancy_sum FROM
(SELECT COUNT(keyword) * 2 AS relevancy, foreign_id
$q->parseQuery($dql); FROM search_index
$coll = $q->execute(array('orm')); WHERE keyword = 'doctrine'
GROUP BY foreign_id
$this->assertEqual($coll[0]->relevancy, 2); UNION
$this->assertEqual($coll[1]->relevancy, 0); SELECT COUNT(keyword) AS relevancy, foreign_id
FROM search_index) AS query_alias
WHERE keyword = 'dbal' AND (position + 1) = (SELECT position FROM search_index WHERE keyword = 'database')
GROUP BY foreign_id
WHERE search_test_id IN (SELECT search_test_id FROM search_test_index
WHERE keyword = ?)
AND seach_test_id IN (SELECT search_test_id FROM search_test_index
WHERE keyword = 'dbal'
AND (position + 1) = (SELECT position FROM search_index WHERE keyword = 'database')
GROUP BY foreign_id
ORDER BY relevancy_sum";
} }
*/
} }