public function searchTopics($query, $sort = array(), $limit = null, $locale = null)
{
$meta = $this->getClassMetadata();
$config = $this->listener->getConfiguration($this->_em, $meta->name);
$qb = $this->getQueryBuilder()->select('t', 'tt')->from($config['useObjectClass'], 't')->leftJoin('t.translations', 'tt')->where("tt.field = 'title'");
$orX = $qb->expr()->orx();
$orX->add($qb->expr()->like('t.title', $qb->expr()->literal("%{$query}%")));
$orX->add($qb->expr()->like('tt.content', $qb->expr()->literal("%{$query}%")));
$qb->andWhere($orX);
if (!empty($sort) && is_array($sort)) {
foreach ($sort as $sortColumn => $sortDir) {
$qb->addOrderBy('t.' . $sortColumn, $sortDir);
}
}
if (!is_null($limit)) {
$qb->setMaxResults($limit);
}
return $this->setTranslatableHint($qb->getQuery(), $locale);
}