private function getIdsQuery(
        $collection = null,
        $systemCollections = true,
        $types = null,
        $search = null,
        $orderBy = null,
        $orderSort = null,
        $limit = null,
        $offset = null,
        $select = 'media.id'
    ) {
        $queryBuilder = $this->createQueryBuilder('media')->select($select);

        $queryBuilder->innerJoin('media.collection', 'collection');

        if (!empty($collection)) {
            $queryBuilder->andWhere('collection.id = :collection');
            $queryBuilder->setParameter('collection', $collection);
        }

        if (!$systemCollections) {
            $queryBuilder->leftJoin('collection.type', 'collectionType');
            $queryBuilder->andWhere(
                sprintf('collectionType.key != \'%s\'', SystemCollectionManagerInterface::COLLECTION_TYPE)
            );
        }

        if (!empty($types)) {
            $queryBuilder->innerJoin('media.type', 'type');
            $queryBuilder->andWhere('type.name IN (:types)');
            $queryBuilder->setParameter('types', $types);
        }

        if (!empty($search)) {
            $queryBuilder
                ->innerJoin('media.files', 'file')
                ->innerJoin('file.fileVersions', 'fileVersion', 'WITH', 'fileVersion.version = file.version')
                ->leftJoin('fileVersion.meta', 'fileVersionMeta');

            $queryBuilder->andWhere('fileVersionMeta.title LIKE :search');
            $queryBuilder->setParameter('search', '%' . $search . '%');
        }

        if ($offset) {
            $queryBuilder->setFirstResult($offset);
        }

        if ($limit) {
            $queryBuilder->setMaxResults($limit);
        }

        if (!empty($orderBy)) {
            $queryBuilder->addOrderBy($orderBy, $orderSort);
        }

        return $queryBuilder->getQuery();
    }