Skip to content

Instantly share code, notes, and snippets.

@phpfour
Created November 27, 2015 08:49
Show Gist options
  • Select an option

  • Save phpfour/70cd4bd4231a1ab83624 to your computer and use it in GitHub Desktop.

Select an option

Save phpfour/70cd4bd4231a1ab83624 to your computer and use it in GitHub Desktop.
Keyword Filter
<?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