我有以下查询:
$query = $qb->select('DISTINCT s')
->from("MainBundle:Shop", 's')
->andWhere('SOUNDEX(s.fullname) = SOUNDEX(:shopName)');
$parameter["shopName"] = $searchquery;
$query->setParameters($parameter);
$query = $qb->select('DISTINCT s')
->from("MainBundle:Shop", 's')
->andWhere($qb->expr()->like('s.fullname', $qb->expr()->literal('%' . $searchquery . '%')));
有可能两个将这两个查询合并为一个吗?
答案 0 :(得分:1)
如果你的第二个查询有效,这应该有效:
$em = $this->getEntityManager();
$qb = $em->createQuery('
SELECT DISTINCT s
FROM MainBundle:Shop p
WHERE Soundex(s.fullname) = :soundex(shopname) OR
($qb->expr()->like('s.fullname', $qb->expr()->literal('%' . $searchquery . '%')))
');
$parameter["shopName"] = $searchquery;
$query->setParameters($parameter);