Commit 5b611b53 authored by zYne's avatar zYne

--no commit message

--no commit message
parent 201f821b
...@@ -178,9 +178,18 @@ class Doctrine_Search_Query ...@@ -178,9 +178,18 @@ class Doctrine_Search_Query
if (is_array($term)) { if (is_array($term)) {
$parsed = $this->parseTerms($term); $parsed = $this->parseTerms($term);
} else { } else {
$parsed = $this->parseClause($term); if (strpos($term, '(') === false) {
$parsed = $foreignId . ' IN (SELECT ' . $foreignId . ' FROM ' . $this->_table->getTableName() . ' WHERE ' . $this->parseClause($term) . ')';
} else {
$parsed = $this->parseClause($term);
}
}
if (strlen($parsed) > 20) {
$ret[] = '(' . $parsed . ')';
} else {
$ret[] = $parsed;
} }
$ret[] = $foreignId . ' IN (SELECT ' . $foreignId . ' FROM ' . $this->_table->getTableName() . ' WHERE ' . $parsed . ')';
} }
$r = implode(' AND ', $ret); $r = implode(' AND ', $ret);
...@@ -193,35 +202,25 @@ class Doctrine_Search_Query ...@@ -193,35 +202,25 @@ class Doctrine_Search_Query
} }
public function parseTerms(array $terms) public function parseTerms(array $terms)
{ {
$foreignId = current(array_diff($this->_table->getColumnNames(), array('keyword', 'field', 'position')));
if (count($terms) > 1) { if (count($terms) > 1) {
$ret = array(); $ret = array();
foreach ($terms as $term) { foreach ($terms as $term) {
$parsed = $this->parseClause($term); $ret[] = $this->parseClause($term);
if (strlen($parsed) > 20) {
$ret[] = '(' . $parsed. ')';
} else {
$ret[] = $parsed;
}
} }
$parsed = implode(' OR ', $ret);
if (strpos($parsed, '(') === false) {
$parsed = $foreignId . ' IN (SELECT ' . $foreignId . ' FROM ' . $this->_table->getTableName() . ' WHERE ' . $parsed . ')';
}
return implode(' OR ', $ret); return $parsed;
} else { } else {
$ret = $this->parseTerm($terms[0]); $ret = $this->parseTerm($terms[0]);
return $ret[0]; return $ret[0];
} }
} }
public function parseAndSeparatedTerms($terms, $foreignId)
{
$ret = array();
foreach ($terms as $term) {
$parsed = $this->parseClause($term);
$ret[] = $foreignId . ' IN (SELECT ' . $foreignId . ' FROM ' . $this->_table->getTableName() . ' WHERE ' . $parsed . ')';
}
$r = implode(' AND ', $ret);
}
public function parseTerm($term) public function parseTerm($term)
{ {
if (strpos($term, "'") === false) { if (strpos($term, "'") === false) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment