gpt4 book ai didi

symfony - Symfony2/弹性束

转载 作者:行者123 更新时间:2023-12-03 01:45:40 25 4
gpt4 key购买 nike

我刚刚安装了带有Elastica bundle 软件的symfony2项目,elasticsearch正在运行。
我已经配置了fos_elastica,以便我的实体(例如汽车)将在Elasticsearch中自动重新索引。
一切正常。

运作方式如下:

在我的 Controller 中

$em->flush();

然后,当实体保留在数据库中时,它将调用
$this->dispatchPostFlushEvent();

现在在ContainerAwareEventManager.php中,我可以找到方法dispatch事件,该事件将引发一个事件以在 Elasticsearch 中为实体重新编制索引(在dispatchEvent()中)

我希望做的是手动而不是自动引发此事件

我的意思是这种用法:
$em->flush();
$em->flushAndReindexEs();

要么
$em->flush()
$this->raiseEvent('reindex-elastic-entity', $em, array('title' => 'string')

有人看到做这种事情的简单方法吗?

我继续研究dispatchEvent。

任何帮助都会有所帮助;)
谢谢

最佳答案

FOSElasticaBundle实现事件侦听器,该事件侦听器在postFlush事件上发送更新。

因此,您需要实现自己的事件侦听器,该事件侦听器将收集有关计划的(用于持久,更新或删除)实体的信息(您可以查看FOS\ElasticaBundle\Doctrine\Listener作为示例),以及事件侦听器,它将捕获您将触发的自己的事件手动-将更新发送到ES(通过FOS\ElasticaBundle\Persister\ObjectPersister)。

您也可以看看this example

关于symfony - Symfony2/弹性束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44139728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com