public function createQueryWithSearch(Search $search) { $qb = $this->createQueryBuilder('f'); if ('votes_desc' == $search->orderBy()) { $qb->orderBy('f.votes', 'DESC'); } elseif ('votes_asc' == $search->orderBy()) { $qb->orderBy('f.votes', 'ASC'); } if ($search->search()) { $qb->andWhere('f.quotes like :author'); if ($search->exactMatching()) { $qb->setParameter('author', sprintf('%%<%s>%%', $search->search())); } else { $qb->setParameter('author', sprintf('%%%s%%', $search->search())); } } return $qb->addOrderBy('f.createdAt', 'DESC'); }