0

我有以下查询:

  $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 . '%')));

是否有可能将这两个查询合并为一个?

4

1 回答 1

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);
于 2013-10-11T07:56:41.920 回答