protected function buildQueryBuilderForRelationMap($relationMap)
    {
        /** @var QueryBuilder $queryBuilder */
        $queryBuilder = $this->entityManager->createQueryBuilder();

        $queryBuilder->select('n')
            ->from(NodeData::class, 'n');

        $constraints = [];
        $parameters = [];

        foreach ($relationMap as $relatedObjectType => $relatedIdentifiers) {
            foreach ($relatedIdentifiers as $relatedIdentifier) {
                // entity references like "__identifier": "so-me-uu-id"
                $constraints[] = '(LOWER(NEOSCR_TOSTRING(n.properties)) LIKE :entity' . md5($relatedIdentifier) . ' )';
                $parameters['entity' . md5($relatedIdentifier)] = '%"__identifier": "' . strtolower($relatedIdentifier) . '"%';

                // asset references in text like "asset://so-me-uu-id"
                $constraints[] = '(LOWER(NEOSCR_TOSTRING(n.properties)) LIKE :asset' . md5($relatedIdentifier) . ' )';
                switch ($this->entityManager->getConnection()->getDatabasePlatform()->getName()) {
                    case 'postgresql':
                        $parameters['asset' . md5($relatedIdentifier)] = '%asset://' . strtolower($relatedIdentifier) . '%';
                    break;
                    case 'sqlite':
                        $parameters['asset' . md5($relatedIdentifier)] = '%asset:\/\/' . strtolower($relatedIdentifier) . '%';
                    break;
                    default:
                        $parameters['asset' . md5($relatedIdentifier)] = '%asset:\\\\/\\\\/' . strtolower($relatedIdentifier) . '%';
                }
            }
        }

        $queryBuilder->where(implode(' OR ', $constraints));
        $queryBuilder->setParameters($parameters);
        return $queryBuilder;
    }