From fb58fb65986bbbce9b8740415ea05320977ed646 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 16 Jul 2007 19:26:14 +0000 Subject: [PATCH] --- lib/Doctrine/Search/Query.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/Search/Query.php b/lib/Doctrine/Search/Query.php index 1fef6114e..2d8f4849d 100644 --- a/lib/Doctrine/Search/Query.php +++ b/lib/Doctrine/Search/Query.php @@ -77,13 +77,34 @@ class Doctrine_Search_Query $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) { - $a = array(); + $condition = array(); + $subcondition = array(); 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); } }