1
0
mirror of synced 2024-12-14 23:26:04 +03:00
This commit is contained in:
zYne 2007-07-16 19:26:14 +00:00
parent 4226685f3c
commit fb58fb6598

View File

@ -77,13 +77,34 @@ class Doctrine_Search_Query
$terms = Doctrine_Tokenizer::quoteExplode($text); $terms = Doctrine_Tokenizer::quoteExplode($text);
$map = $this->_query->getRootDeclaration();
$rootAlias = $this->_query->getRootAlias();
$component = $map['table']->getComponentName() . 'Index';
$subAlias = 'i2';
$rel = $map['table']->getRelation($component);
$foreign = (array) $rel->getForeign();
foreach ((array) $rel->getLocal() as $k => $field) {
$joinCondition = $rootAlias . '.' . $field . ' = ' . $subAlias . '.' . $foreign[$k];
}
$this->_query->innerJoin($rootAlias . '.' . $component . ' ' . 'i');
foreach ($this->_aliases as $alias) { foreach ($this->_aliases as $alias) {
$a = array(); $condition = array();
$subcondition = array();
foreach ($terms as $term) { foreach ($terms as $term) {
$a[] = 'i.keyword = ?'; $condition[] = $alias . '.keyword = ?';
$subcondition[] = $subAlias . '.keyword = ?';
} }
$this->_query->addWhere(implode(' OR ', $a), $terms); $this->_query->addSelect('(SELECT COUNT(' . $subAlias . '.position) FROM '
. $component . ' ' . $subAlias . ' WHERE '
. implode(' OR ', $subcondition) . ' AND ' . $joinCondition . ') relevancy');
$this->_query->addWhere(implode(' OR ', $condition), $terms);
} }
} }