使用正则表达式优化Doctrine WHERE子句

时间:2012-06-07 14:21:08

标签: doctrine doctrine-orm dql

请参阅以下Doctrine查询:

SELECT values, orgunit, form 
    FROM Values values 
    INNER JOIN values.orgunit orgunit 
    INNER JOIN values.form form 
    INNER JOIN orgunit.orgunitStructure orgunitStructure 
    WHERE orgunitStructure.level1Id=123032 
        AND orgunitStructure.level >= (SELECT selectedOrgSructure.level FROM OrgunitStructure selectedOrgSructure WHERE selectedOrgSructure.orgunit=123032 ) 
        AND form.id IN(189,187,190,188) 
        AND ( 
            LOWER(values.value) LIKE '%"189886":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189880":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189881":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189871":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189888":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189873":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189870":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189863":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189865":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189867":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189869":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189872":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189894":"10369434"%' 
            OR LOWER(values.value) LIKE '%"189896":"10369434"%' 
            OR LOWER(orgunit.longname) LIKE '%10369434%'
            )

我正在寻找WHERE子句的REGEX优化,特别是将OR组合在一起,如下所示:

LOWER(values.value) LIKE '%"189886":"10369434"%' 
OR LOWER(values.value) LIKE '%"189880":"10369434"%' 
OR LOWER(values.value) LIKE '%"189881":"10369434"%' 
OR LOWER(values.value) LIKE '%"189871":"10369434"%' 
OR LOWER(values.value) LIKE '%"189888":"10369434"%' 
OR LOWER(values.value) LIKE '%"189873":"10369434"%' 
OR LOWER(values.value) LIKE '%"189870":"10369434"%' 

分为:

LOWER(values.value) REGEXP '%("189886":"10369434")|("189886":"10369434")|("189880":"10369434")|("189881":"10369434")|("189871":"10369434")|("189888":"10369434")|("189873":"10369434")%' 

0 个答案:

没有答案