【问题标题】:Auto index child objects in fos elasticafos elastica 中的自动索引子对象
【发布时间】:2014-02-28 16:15:57
【问题描述】:

我在 config.yml 中创建了一个弹性搜索映射,它使用了学说 orm,问题是当我创建一个新文档时,索引会自动填充最顶层的对象,即“文档”,而不是任何子对象诸如“文件夹,作者,评论...”之类的对象,有人可以建议我是否缺少任何标志或任何设置。下面是我的 Elastica 配置:

# Elastica Configuration
fos_elastica:
    clients:
        default: { host: localhost, port: 9200 }
    indexes:
        website:
            client: default
            index_name: docova
            types:
                documents:
                    mappings:
                        Doc_Title: ~
                        Description: ~
                        Date_Created: ~
                        Doc_Status: ~
                        Keywords: ~
                        folder:
                           type: "object"
                           properties:
                              id: ~
                              Library:
                                 type: "object"
                                 properties:
                                    id: ~
                        Author:
                           type: "object"
                           properties:
                              username: ~
                        Comments:
                           type: "object"
                           properties:
                              comment: ~
                        Form_Values:
                           type: "object"
                           properties:
                              Field_Value: ~
                        Bookmarks:
                           type: "object"
                           properties:
                              Target_Folder:
                                  type: "object"
                                  properties:
                                     id: ~
                        DocType:
                           type: "object"
                           properties:
                               id: ~
                               Doc_Name: ~
                        Attachments:
                           type: "object"
                           properties:
                              File_Name:
                              content:
                                 type: attachment 
                    persistence:
                        driver: orm
                        model: Docova\DocovaBundle\Entity\Documents
                        provider: ~
                        listener: ~
                        finder: ~

谢谢。

【问题讨论】:

    标签: symfony foselasticabundle


    【解决方案1】:

    我在这里找到了解决方案。 Symfony2 FOSElasticaBundle update index for all entities related to the entity updated

    注意:在我的 FOSElastica 版本中,Listener 不在 ORM 文件夹中,而是在 FOS\ElasticaBundle\Doctrine 中,并且参数已从 LifecycleEventArgs $eventArgs 更改为 \Doctrine\Common\EventArgs $eventArgs。

    编辑:对于这种情况,您也必须覆盖 postPersist。

    public function postPersist(\Doctrine\Common\EventArgs $eventArgs)
    {
    
        $entity = $eventArgs->getEntity();
    
    
        if ($entity instanceof $this->objectClass && $this->isObjectIndexable($entity)) {
    
            $this->scheduledForInsertion[] = $entity;
            $this->inicializaPost();
            $this->objectPersisterPost->replaceOne($entity->getPost());
        }
    }
    

    【讨论】:

    • isObjectIndexable - 成员拥有 provate 访问权限,并且有错误运行时注意:Artel\SiteBundle\EventListener\ElasticaCourseListener::postUpdate() 的声明应与 FOS\ElasticaBundle\Doctrine\Listener::postUpdate 兼容(Doctrine\Common\Persistence\Event\LifecycleEventArgs $eventArgs)
    猜你喜欢
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-15
    • 1970-01-01
    相关资源
    最近更新 更多