floriansemm / SolrBundle

Solr-Integration into Symfony and Doctrine2
http://floriansemm.github.io/SolrBundle
MIT License
123 stars 73 forks source link

Other types of mapping #167

Closed AntonioCS closed 7 years ago

AntonioCS commented 7 years ago

Hey,

I am working on a project that depends on entities that are provided by third party bundles (in the vendor folder). Is there any way to create the mappings without using the annotations? Some yml, json or xml mappings that will do the same as the annotations but without having to change the entities?

Thanks!

floriansemm commented 7 years ago

Only annotations are supported.

AntonioCS commented 7 years ago

Well.. that is unfortunate.. Any plans in the pipeline to use anything else besides annotations?

floriansemm commented 7 years ago

no because there are no requests for this features (excepting you)

AntonioCS commented 7 years ago

Would this be something complicated to add? I can't change the way things are due to legacy issues and those entities I am dependent on being in the vendor folder.

floriansemm commented 7 years ago

I have never think about it how to implement a new mapping. So I don't know how complicated it would be.

To solve your problem: you can implement a DTO which uses the vendor-entity:

class WrapperDTO
{
    /** @Solr\Field() */
    private $vendorProperty1;

    /** @Solr\Field() */
    private $vendorProperty2;

    public function __construct($vendorEntity)
    {
        $this->vendorProperty1 = $vendorEntity->getProperty1();
        $this->vendorProperty2 = $vendorEntity->getProperty2();
    }
}
AntonioCS commented 7 years ago

I can't see how I am going to load this when I run the populate command. I see that the entity will be passed in the construct but how do I wire this up? As a service? How will your bundle read this exactly?

Sorry I am just not understanding fully your solution.

floriansemm commented 7 years ago

You can't use the existing populate command. You have to implement your own. It would be something like this:


// fetch all vendor-entities
foreach ($vendorEntity as $vendorEntity) {
    $dto = new WrapperDTO($vendorEntity);
    $this->get('solr.client')->updateDocument($dto);
}
AntonioCS commented 7 years ago

Great! I was already implementing a "hook" on your populate command so that I could populate solr with the missing entity.

Thanks again for all your help.