protected function setSearch(Metadata\EntityMetadata $metadata, array $mapping)
    {
        $clientKey = isset($mapping['key']) ? $mapping['key'] : null;
        if (null === $clientKey) {
            // Search is not enabled for this model.
            return $metadata;
        }

        $factory = $this->getSearchMetadataFactory($clientKey);

        $search = $factory->createInstance($mapping);

        $metadata->setSearch($search);
        return $metadata;
    }