Updating nested object

1,773 views
Skip to first unread message

Cassiano Tartari

unread,
Sep 27, 2013, 2:03:49 PM9/27/13
to elastica-...@googlegroups.com
Hello!

   I am with a problem. I'm using FOSElasticaBundle and I have the following problem: I want to map an doctrine object with nested objects. For example: a post with nested comments, and I would like to update a comment and automatically update a post. For example:

            types:
                post:
                    mappings:
                        name: { boost: 10.0, analyzer: default }
                        comments:
                          type: "nested"
                          properties:
                              title: ~
                              content: ~

But when I update just a single comment the string inside the correspond post doesn't update.

Can somebody help me?

ruflin

unread,
Oct 1, 2013, 7:09:57 AM10/1/13
to elastica-...@googlegroups.com
Hi Cassiano

Probably its better to ask this directly in the FOSElasticaBundle group as this is related to Symfony (I think) and not directly to Elastica.

Cassiano Tartari

unread,
Oct 1, 2013, 7:15:58 AM10/1/13
to elastica-php-client
Tks! I found the solution, there is no docs about this, but I studied the code and now I have a listener for the child nodes that update the fathers when something is changed.

Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


On Tue, Oct 1, 2013 at 8:09 AM, ruflin <ruf...@gmail.com> wrote:
Hi Cassiano

Probably its better to ask this directly in the FOSElasticaBundle group as this is related to Symfony (I think) and not directly to Elastica.

--
You received this message because you are subscribed to the Google Groups "Elastica - Elasticsearch PHP Client" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elastica-php-cl...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Message has been deleted

David lin

unread,
Jan 10, 2014, 1:11:28 AM1/10/14
to elastica-...@googlegroups.com
Can you shared what you've got ? Thanks.


On Tuesday, 1 October 2013 21:15:58 UTC+10, Cassiano Tartari wrote:
Tks! I found the solution, there is no docs about this, but I studied the code and now I have a listener for the child nodes that update the fathers when something is changed.

Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


On Tue, Oct 1, 2013 at 8:09 AM, ruflin <ruf...@gmail.com> wrote:
Hi Cassiano

Probably its better to ask this directly in the FOSElasticaBundle group as this is related to Symfony (I think) and not directly to Elastica.

--
You received this message because you are subscribed to the Google Groups "Elastica - Elasticsearch PHP Client" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elastica-php-client+unsub...@googlegroups.com.

Cassiano Tartari

unread,
Jan 10, 2014, 4:49:49 AM1/10/14
to elastica-php-client
Entity Material has relation with Example, the code is something like this:

<?php

namespace  Company\MyBundle\Listener;

use FOS\ElasticaBundle\Doctrine\ORM\Listener as BaseListener;
use Doctrine\ORM\Event\LifecycleEventArgs;

class ExampleListener extends BaseListener
{
   
    /** @var \Symfony\Component\DependencyInjection\ContainerInterface */
    private $container;

    public function setContainer(\Symfony\Component\DependencyInjection\ContainerInterface $container) {
        $this->container = $container;
    }
   
    protected function inicializaMaterial() {
        $this->objectPersisterMaterial = $this->container->get('fos_elastica.object_persister.search_engine.material');
        $this->em = $this->container->get('doctrine')->getEntityManager();
    }

    /**
     * @param \Doctrine\ORM\Event\LifecycleEventArgs $eventArgs
     */
    public function postUpdate(LifecycleEventArgs $eventArgs)
    {
        /** @var $entity Story */
        $entity = $eventArgs->getEntity();

        if ($entity instanceof $this->objectClass) {
            if ($this->isObjectIndexable($entity)) {
                $this->objectPersister->replaceOne($entity);
                $this->inicializaMaterial();
                foreach ($entity->getMateriais() as $material) {
                    $this->objectPersisterMaterial->replaceOne($material);
                }
            } else {
                $this->scheduleForRemoval($entity, $eventArgs->getEntityManager());
                $this->removeIfScheduled($entity);
            }
        }
    }
}


The service:

   
  fos_elastica.listener.search_engine.example:
    class: 'Company\MyBundle\Listener\ExampleListener'
    arguments:
        - '@fos_elastica.object_persister.search_engine.example'
        - 'Company\MyBundle\Entity\Example'
        - ['postPersist', 'postUpdate', 'postRemove', 'preRemove']
        - id
    calls:
        - [ setContainer, [ '@service_container' ] ]
    tags:
        - { name: 'doctrine.event_subscriber' }

Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


To unsubscribe from this group and stop receiving emails from it, send an email to elastica-php-cl...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages