From d59f761da0959cce6d0b48a23d98649032f28297 Mon Sep 17 00:00:00 2001 From: zYne Date: Wed, 1 Aug 2007 19:37:28 +0000 Subject: [PATCH] --- lib/Doctrine/Connection/UnitOfWork.php | 26 ++++----- lib/Doctrine/DataType.php | 49 ++++++++++++++++ lib/Doctrine/Search/Query.php | 81 +++++++++++--------------- 3 files changed, 92 insertions(+), 64 deletions(-) create mode 100644 lib/Doctrine/DataType.php diff --git a/lib/Doctrine/Connection/UnitOfWork.php b/lib/Doctrine/Connection/UnitOfWork.php index 980d80d8d..4fb4e8e2f 100644 --- a/lib/Doctrine/Connection/UnitOfWork.php +++ b/lib/Doctrine/Connection/UnitOfWork.php @@ -140,7 +140,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module public function saveGraph(Doctrine_Record $record) { $conn = $this->getConnection(); - + $state = $record->state(); if ($state === Doctrine_Record::STATE_LOCKED) { return false; @@ -156,11 +156,11 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module if ($record->isValid()) { $event = new Doctrine_Event($record, Doctrine_Event::RECORD_SAVE); - + $record->preSave($event); $record->getTable()->getRecordListener()->preSave($event); - + if ( ! $event->skipOperation) { switch ($state) { case Doctrine_Record::STATE_TDIRTY: @@ -176,7 +176,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module break; } } - + $record->getTable()->getRecordListener()->postSave($event); $record->postSave($event); @@ -299,13 +299,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module $foreign = $rel->getForeign(); if ($rel instanceof Doctrine_Relation_ForeignKey) { - //if ( ! $record->exists()) { - $saveLater[$k] = $rel; - /** - } else { - $v->save($this->conn); - } - */ + $saveLater[$k] = $rel; } elseif ($rel instanceof Doctrine_Relation_LocalKey) { // ONE-TO-ONE relationship $obj = $record->get($rel->getAlias()); @@ -353,7 +347,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module } foreach ($v->getInsertDiff() as $r) { - + $assocRecord = $assocTable->create(); $assocRecord->set($rel->getForeign(), $r); @@ -428,14 +422,14 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module public function update(Doctrine_Record $record) { $event = new Doctrine_Event($record, Doctrine_Event::RECORD_UPDATE); - + $record->preUpdate($event); $record->getTable()->getRecordListener()->preUpdate($event); - + if ( ! $event->skipOperation) { $array = $record->getPrepared(); - + if (empty($array)) { return false; } @@ -457,7 +451,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module } } } - + $params = array_values($array); $id = $record->identifier(); diff --git a/lib/Doctrine/DataType.php b/lib/Doctrine/DataType.php new file mode 100644 index 000000000..4ae0e96e2 --- /dev/null +++ b/lib/Doctrine/DataType.php @@ -0,0 +1,49 @@ +. + */ + +/** + * Doctrine_DataType + * + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision: 1986 $ + * @author Konsta Vesterinen + */ +class Doctrine_DataType +{ + public function __construct() + { + + } + + public function getName() + { + + } + + public function getDefaultLength() + { + + } +} diff --git a/lib/Doctrine/Search/Query.php b/lib/Doctrine/Search/Query.php index f53c03e69..3297d6aef 100644 --- a/lib/Doctrine/Search/Query.php +++ b/lib/Doctrine/Search/Query.php @@ -71,54 +71,23 @@ class Doctrine_Search_Query { $text = strtolower(trim($text)); - $terms = Doctrine_Tokenizer::sqlExplode($text, ' AND ', '(', ')'); - $foreignId = current(array_diff($this->_table->getColumnNames(), array('keyword', 'field', 'position'))); - - $numTerms = count($terms); - + $weighted = false; if (strpos($text, '^') === false) { $select = 'SELECT COUNT(keyword) AS relevance, ' . $foreignId; $from = 'FROM ' . $this->_table->getTableName(); } else { // organize terms according weights - - foreach ($terms as $k => $term) { - $e = explode('^', $term); - $x = (isset($e[1]) && is_numeric($e[1])) ? $e[1] : 1; - - $weightedTerms[$x][] = $term; - } $weighted = true; $select = 'SELECT SUM(sub_relevance) AS relevance, ' . $foreignId; $from = 'FROM ' ; } - - switch ($numTerms) { - case 0: - return false; - break; - case 1: - // only one term found, use fast and simple query - $data = $this->parseTerm($terms[0]); - $where = $data[0]; - $params = $data[1]; - break; - default: - $where = 'WHERE '; - $cond = array(); - $params = array(); - - foreach ($terms as $term) { - $data = $this->parseTerm($term); - $params = array_merge($params, $data[1]); - $cond[] = $foreignId . ' IN (SELECT ' . $foreignId . ' FROM ' . $this->_table->getTableName() . ' ' . $data[0] . ')'; - } - $where .= implode(' AND ', $cond); - } + $where = 'WHERE '; + $where .= $this->parseClause($text); + $groupby = 'GROUP BY ' . $foreignId; $orderby = 'ORDER BY relevance'; @@ -126,6 +95,7 @@ class Doctrine_Search_Query } public function tokenizeClause($clause) { + $clause = strtolower(trim($clause)); $clause = Doctrine_Tokenizer::bracketTrim($clause); $terms = Doctrine_Tokenizer::sqlExplode($clause, ' ', '(', ')'); @@ -141,25 +111,30 @@ class Doctrine_Search_Query foreach ($terms as $k => $term) { $term = trim($term); - if ($term === 'AND') { + if ($term === 'and') { $operator = self::OPERATOR_AND; - } elseif ($term === 'OR') { + } elseif ($term === 'or') { $operator = self::OPERATOR_OR; } else { if ($operator === self::OPERATOR_OR) { - if ( ! is_array($ret[($i-1)])) { - $ret[($i-1)] = array($ret[($i-1)], $term); - } else { - $ret[($i-1)][] = $term; - } - } else { - $ret[$i] = $term; - + $ret[$i] = $term; $i++; + } else { + if ($k === 0) { + $ret[$i] = $term; + $i++; + } else { + if ( ! is_array($ret[($i - 1)])) { + $ret[($i - 1)] = array_merge(array($ret[($i - 1)]), array($term)); + } else { + $ret[($i - 1)][] = $term; + } + } } $operator = self::OPERATOR_AND; } } + return $ret; } @@ -179,7 +154,13 @@ class Doctrine_Search_Query $parsed = $this->parseTerms($term); } else { if (strpos($term, '(') === false) { - $parsed = $foreignId . ' IN (SELECT ' . $foreignId . ' FROM ' . $this->_table->getTableName() . ' WHERE ' . $this->parseClause($term) . ')'; + if (substr($term, 0, 1) === '-') { + $operator = 'NOT IN'; + $term = substr($term, 1); + } else { + $operator = 'IN'; + } + $parsed = $foreignId . ' ' . $operator . ' (SELECT ' . $foreignId . ' FROM ' . $this->_table->getTableName() . ' WHERE ' . $this->parseClause($term) . ')'; } else { $parsed = $this->parseClause($term); } @@ -213,7 +194,7 @@ class Doctrine_Search_Query if (strpos($parsed, '(') === false) { $parsed = $foreignId . ' IN (SELECT ' . $foreignId . ' FROM ' . $this->_table->getTableName() . ' WHERE ' . $parsed . ')'; - } + } return $parsed; } else { @@ -223,7 +204,11 @@ class Doctrine_Search_Query } public function parseTerm($term) { + $negation = false; + + if (strpos($term, "'") === false) { + $where = 'keyword = ?'; $params = array($term); @@ -239,7 +224,7 @@ class Doctrine_Search_Query } $where .= ' AND (position + ' . $k . ') = (SELECT position FROM ' . $this->_table->getTableName() . ' WHERE keyword = ?)'; } - } + } return array($where, $params); }