This commit is contained in:
parent
20ca9109aa
commit
201f821b27
@ -162,47 +162,54 @@ class Doctrine_Search_Query
|
|||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseClause($clause)
|
public function parseClause($clause)
|
||||||
{
|
{
|
||||||
$clause = Doctrine_Tokenizer::bracketTrim($clause);
|
$clause = Doctrine_Tokenizer::bracketTrim($clause);
|
||||||
|
|
||||||
$foreignId = current(array_diff($this->_table->getColumnNames(), array('keyword', 'field', 'position')));
|
$foreignId = current(array_diff($this->_table->getColumnNames(), array('keyword', 'field', 'position')));
|
||||||
|
|
||||||
$terms = Doctrine_Tokenizer::sqlExplode($clause, ' ', '(', ')');
|
$terms = $this->tokenizeClause($clause);
|
||||||
|
|
||||||
foreach ($terms as $k => $term) {
|
|
||||||
$terms[$k] = $term;
|
|
||||||
}
|
|
||||||
|
|
||||||
$terms = Doctrine_Tokenizer::sqlExplode($clause, ' AND ', '(', ')');
|
|
||||||
|
|
||||||
if (count($terms) > 1) {
|
if (count($terms) > 1) {
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
|
||||||
foreach ($terms as $term) {
|
foreach ($terms as $term) {
|
||||||
|
if (is_array($term)) {
|
||||||
|
$parsed = $this->parseTerms($term);
|
||||||
|
} else {
|
||||||
$parsed = $this->parseClause($term);
|
$parsed = $this->parseClause($term);
|
||||||
|
}
|
||||||
$ret[] = $foreignId . ' IN (SELECT ' . $foreignId . ' FROM ' . $this->_table->getTableName() . ' WHERE ' . $parsed . ')';
|
$ret[] = $foreignId . ' IN (SELECT ' . $foreignId . ' FROM ' . $this->_table->getTableName() . ' WHERE ' . $parsed . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = implode(' AND ', $ret);
|
$r = implode(' AND ', $ret);
|
||||||
} else {
|
} else {
|
||||||
$terms = Doctrine_Tokenizer::sqlExplode($clause, ' OR ', '(', ')');
|
$terms = (is_array($terms[0])) ? $terms[0] : array($terms[0]);
|
||||||
|
|
||||||
|
return $this->parseTerms($terms);
|
||||||
|
}
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
public function parseTerms(array $terms)
|
||||||
|
{
|
||||||
if (count($terms) > 1) {
|
if (count($terms) > 1) {
|
||||||
$ret = array();
|
$ret = array();
|
||||||
foreach ($terms as $term) {
|
foreach ($terms as $term) {
|
||||||
$ret[] = $this->parseClause($term);
|
$parsed = $this->parseClause($term);
|
||||||
|
if (strlen($parsed) > 20) {
|
||||||
|
$ret[] = '(' . $parsed. ')';
|
||||||
|
} else {
|
||||||
|
$ret[] = $parsed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = implode(' OR ', $ret);
|
return implode(' OR ', $ret);
|
||||||
} else {
|
} else {
|
||||||
$ret = $this->parseTerm($clause);
|
$ret = $this->parseTerm($terms[0]);
|
||||||
return $ret[0];
|
return $ret[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $r;
|
|
||||||
}
|
|
||||||
public function parseAndSeparatedTerms($terms, $foreignId)
|
public function parseAndSeparatedTerms($terms, $foreignId)
|
||||||
{
|
{
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user