floriansemm / SolrBundle

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

Find - problem #136

Closed hanzx closed 8 years ago

hanzx commented 8 years ago

Hi Florian,

  $repo = $this->get('solr.client')->getRepository('AppBundle:Solr\Product');
        $product = $repo->find('0000396-1341');

Symfony profiler -> Solr Queries -> parameters -> omitHeader=true wt=json json.nl=flat q=id:product_0000396-1341 start=0 rows=10 fl=*,score

I need there id:0000396-1341? Thanks

floriansemm commented 8 years ago

Try this:

$query = $this->get('solr.client')->createQuery('AcmeDemoBundle:Post');
$query->addSearchTerm('id', '0000396-1341');

$result = $query->getResult();
hanzx commented 8 years ago

i know, i only show you),but my problem is

Hydration mode is HYDRATE_INDEX

class ValueHydrator implements HydratorInterface
{
    /**
     * {@inheritdoc}
     */
    public function hydrate($document, MetaInformationInterface $metaInformation)
    {
        $targetEntity = $metaInformation->getEntity();

        $reflectionClass = new \ReflectionClass($targetEntity);
        foreach ($document as $property => $value) {
            if ($property === MetaInformationInterface::DOCUMENT_KEY_FIELD_NAME) {
                $value = $this->removePrefixedKeyFieldName($value);
            }

            // skip field if value is array or "flat" object
            // hydrated object should contain a list of real entities / entity
            if ($this->isComplexValue($property, $value, $metaInformation)) {
                continue;
            }

return

1

when i comment isComplexValue

class ValueHydrator implements HydratorInterface
{
    /**
     * {@inheritdoc}
     */
    public function hydrate($document, MetaInformationInterface $metaInformation)
    {
        $targetEntity = $metaInformation->getEntity();

        $reflectionClass = new \ReflectionClass($targetEntity);
        foreach ($document as $property => $value) {
            if ($property === MetaInformationInterface::DOCUMENT_KEY_FIELD_NAME) {
                $value = $this->removePrefixedKeyFieldName($value);
            }

            // skip field if value is array or "flat" object
            // hydrated object should contain a list of real entities / entity
            /*if ($this->isComplexValue($property, $value, $metaInformation)) {
                continue;
            }*/

return this a it is what i need: 2

floriansemm commented 8 years ago

What version do you use? This problem should be fixed with 8714d201c20610148453ad9d612822ee70251cd0

hanzx commented 8 years ago

last 1.5.4

floriansemm commented 8 years ago

please try dev-master!

hanzx commented 8 years ago

cool- thanks11