Created
November 27, 2015 08:49
-
-
Save phpfour/70cd4bd4231a1ab83624 to your computer and use it in GitHub Desktop.
Keyword Filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Docudex\Bundle\DocumentBundle\Search\Filter\Doctrine; | |
| use Doctrine\ORM\Query\Expr; | |
| use Doctrine\ORM\QueryBuilder; | |
| use Docudex\Bundle\DocumentBundle\Search\Filter\FilterInterface; | |
| /** | |
| * Keyword Filter | |
| * | |
| * @author Mohammad Emran Hasan <phpfour@gmail.com> | |
| */ | |
| class KeywordFilter implements FilterInterface | |
| { | |
| public function filter($constraints, QueryBuilder $qb) | |
| { | |
| $qb->innerJoin('DocudexDocumentBundle:Version', 'v', Expr\Join::WITH, 'v = d.latestVersion'); | |
| $qb->andWhere( | |
| $qb->expr()->orX( | |
| $qb->expr()->like('v.title', ':title'), | |
| $qb->expr()->like('v.description', ':description') | |
| )) | |
| ->setParameter('title', '%' . $constraints['keyword'] . '%') | |
| ->setParameter('description', '%' . $constraints['keyword'] . '%'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment