floriansemm / SolrBundle

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

Index 2 fields of a ManyToOne Releation #168

Closed jmogilner closed 5 years ago

jmogilner commented 7 years ago

I'm unable to find a way to index 2 fields (id and name) of a relation. I want to be able to filter by id, and display the name in the results, without doctrine hydration. Is there any way to accomplish this?

Thank you for your work!

floriansemm commented 7 years ago

You must use hydration to filter by this ID, if not you will get only the index relation document

jkwakman commented 6 years ago

I have added a PR for this feature request: https://github.com/floriansemm/SolrBundle/pull/187

I hope Florian is willing to merge some of my work back to the master branche. You can index multiple fields with the following syntax:


    /**
     * @var Tag[] $tag
     *
     * @ORM\OneToMany(targetEntity="Acme\DemoBundle\Entity\Tag", mappedBy="post", cascade={"persist"})
     * @Solr\Fields(getter="getTags", fields={
     *      @Solr\Field(type="integers", getter="getId", fieldAlias="id"),
     *      @Solr\Field(type="strings", getter="getName", fieldAlias="name")
     *      })
     */
    private $tags;
jkwakman commented 6 years ago

Merged all the PR's into one big PR see: https://github.com/floriansemm/SolrBundle/pull/188

You can test this feature before merge by adding the following changes to the composer.json:

"repositories": [ { "type": "vcs", "url": "https://github.com/jkwakman/SolrBundle/" } ], "require": "floriansemm/solr-bundle": "dev-dev-master-composer"