This commit is contained in:
parent
64f7e3a36e
commit
d59f761da0
@ -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();
|
||||
|
||||
|
49
lib/Doctrine/DataType.php
Normal file
49
lib/Doctrine/DataType.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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 <kvesteri@cc.hut.fi>
|
||||
*/
|
||||
class Doctrine_DataType
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getDefaultLength()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user