public function onFilterBuilderPrepare(PrepareEvent $event)
    {
        $qb = $event->getQueryBuilder();

        $queryClasses = array(
            'Doctrine\ORM\QueryBuilder'          => 'Lexik\Bundle\FormFilterBundle\Filter\Doctrine\ORMQuery',
            'Doctrine\DBAL\Query\QueryBuilder'   => 'Lexik\Bundle\FormFilterBundle\Filter\Doctrine\DBALQuery',
            'Doctrine\ODM\MongoDB\Query\Builder' => 'Lexik\Bundle\FormFilterBundle\Filter\Doctrine\MongodbQuery',
        );

        foreach ($queryClasses as $builderClass => $queryClass) {
            if (class_exists($builderClass) && $qb instanceof $builderClass) {
                $query = new $queryClass($qb, $this->getForceCaseInsensitivity($qb), $this->encoding);

                $event->setFilterQuery($query);
                $event->stopPropagation();

                return;
            }
        }
    }