public function search($filterKey, $q = null, $type = null)
    {
        if ($type == 0) {
            $type = null;
        }

        if (!$this->filter->has($filterKey)) {
            return array();
        }

        $qb = $this->entityManager->getRepository($this->class)->createQueryBuilder('m')
            ->select('m.id as id')
            ;

        $filter = $this->filter->get($filterKey);
        if ($filter === null) {
            $qb->where('m.filter IS NULL');
        } else {
            $qb->where('m.filter = :filter')
                ->setParameter('filter', $filter)
                ;
        }

        if ($q !== null) {
            foreach (explode(' ', $q) as $i => $word) {
                $qb->andWhere(
                    $qb->expr()->orX(
                        $qb->expr()->like('m.name', ':q'.$i),
                        $qb->expr()->like('m.description', ':q'.$i),
                        $qb->expr()->like('m.alt', ':q'.$i)
                    )
                )
                ->setParameter('q'.$i, '%'.$word.'%')
                ;
            }
        }

        if ($type != null) {
            $qb->andWhere('m.type = :type')
                ->setParameter('type', $type)
                ;
        }

        $results = $qb->getQuery()
            ->getArrayResult();

        $ids = array();
        foreach ($results as $media) {
            $ids[] = $media['id'];
        }

        return $ids;
    }