0

我正在尝试处理搜索工具中的空格 - 特别是处理名字和姓氏,我可以让我的查询在命令行上工作,但是当我尝试将它们转换为 modx/pdo 语法时没有得到结果。[因为标准翻译不正确]

我所拥有的是:

$criteria->where(array(
    'Entities.first_name:LIKE' => "%$searchQuery%",
    'OR:Entities.cams:LIKE' => "%$searchQuery%",
    'OR:Entities.last_name:LIKE' => "%$searchQuery%",
    'OR:Entities.company:LIKE' => "%$searchQuery%",
    'OR:CONCAT(`Entites`.`first_name`," ",`Entities`.`last_name`):LIKE' => "%$searchQuery%",
        ));

问题出在最后一行 OR:CONCAT 上,如果我转储查询,我的 where 子句如下所示:

WHERE  ( 
`Entities`.`first_name` LIKE '%first last%' 
OR `Entities`.`cams` LIKE '%first last%' 
OR `Entities`.`last_name` LIKE '%first last%' 
OR `Entities`.`company` LIKE '%first last%' 
OR `CONCAT(`Entites`.`first_name`," ",`Entities` LIKE '%first last%' 
)

它在 CONCAT 之前添加一个反引号并省略 . last_name)

什么是正确的语法?

4

1 回答 1

0

高级条件通常需要构造为字符串而不是键 => 值对。

以下对原始查询并不完全正确,但应该给出相同的结果:

$c->where(array(
    'Entities.first_name:LIKE' => "%$searchQuery%",
    'OR:Entities.cams:LIKE' => "%$searchQuery%",
    'OR:Entities.last_name:LIKE' => "%$searchQuery%",
    'OR:Entities.company:LIKE' => "%$searchQuery%",
));
$c->orCondition("CONCAT(Entities.first_name,' ',Entities.last_name) LIKE '%$searchQuery%'");

或者将整组 OR 条件作为字符串传递,以准确重现您的查询:

$c->where("
    Entities.first_name LIKE '%$searchQuery%'
    OR Entities.cams LIKE '%$searchQuery%'
    OR Entities.last_name LIKE '%$searchQuery%'
    OR Entities.company LIKE '%$searchQuery%'
    OR CONCAT(Entities.first_name,' ',Entities.last_name) LIKE '%$searchQuery%'
");
于 2015-02-12T02:24:09.200 回答