wildcard support for search query language
This commit is contained in:
parent
36fa8016e7
commit
97ca7c9c36
@ -32,8 +32,6 @@
|
|||||||
*/
|
*/
|
||||||
class Doctrine_Search_Query
|
class Doctrine_Search_Query
|
||||||
{
|
{
|
||||||
const OPERATOR_OR = 0;
|
|
||||||
const OPERATOR_AND = 1;
|
|
||||||
/**
|
/**
|
||||||
* @var Doctrine_Query $query the base query
|
* @var Doctrine_Query $query the base query
|
||||||
*/
|
*/
|
||||||
@ -45,6 +43,8 @@ class Doctrine_Search_Query
|
|||||||
|
|
||||||
protected $_sql = '';
|
protected $_sql = '';
|
||||||
|
|
||||||
|
protected $_params = array();
|
||||||
|
|
||||||
|
|
||||||
protected $_condition;
|
protected $_condition;
|
||||||
/**
|
/**
|
||||||
@ -186,25 +186,44 @@ class Doctrine_Search_Query
|
|||||||
$negation = false;
|
$negation = false;
|
||||||
|
|
||||||
if (strpos($term, "'") === false) {
|
if (strpos($term, "'") === false) {
|
||||||
$where = 'keyword = ?';
|
$where = $this->parseWord($term);
|
||||||
|
|
||||||
$params = array($term);
|
|
||||||
} else {
|
} else {
|
||||||
$term = trim($term, "' ");
|
$term = trim($term, "' ");
|
||||||
|
|
||||||
$where = 'keyword = ?';
|
|
||||||
$terms = Doctrine_Tokenizer::quoteExplode($term);
|
$terms = Doctrine_Tokenizer::quoteExplode($term);
|
||||||
$params = $terms;
|
$where = $this->parseWord($terms[0]);
|
||||||
|
|
||||||
foreach ($terms as $k => $word) {
|
foreach ($terms as $k => $word) {
|
||||||
if ($k === 0) {
|
if ($k === 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$where .= ' AND (position + ' . $k . ') = (SELECT position FROM ' . $this->_table->getTableName() . ' WHERE keyword = ?)';
|
$where .= ' AND (position + ' . $k . ') = (SELECT position FROM ' . $this->_table->getTableName() . ' WHERE ' . $this->parseWord($word) . ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $where;
|
return $where;
|
||||||
}
|
}
|
||||||
|
public function parseWord($word)
|
||||||
|
{
|
||||||
|
if (strpos($word, '?') !== false ||
|
||||||
|
strpos($word, '*') !== false) {
|
||||||
|
|
||||||
|
$word = str_replace('*', '%', $word);
|
||||||
|
|
||||||
|
$where = 'keyword LIKE ?';
|
||||||
|
|
||||||
|
$params = array($word);
|
||||||
|
} else {
|
||||||
|
$where = 'keyword = ?';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_params[] = $word;
|
||||||
|
|
||||||
|
return $where;
|
||||||
|
}
|
||||||
|
public function getParams()
|
||||||
|
{
|
||||||
|
return $this->_params;
|
||||||
|
}
|
||||||
public function getSql()
|
public function getSql()
|
||||||
{
|
{
|
||||||
return $this->_sql;
|
return $this->_sql;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user