php – Symfony 2 FOQElasticaBundle搜索多个实体

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – Symfony 2 FOQElasticaBundle搜索多个实体脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
开始使用Symfony 2搞乱Elastic SeArch Bundle并且对实体的搜索功能有疑问.

如果您有这样的配置:

foq_elastica:
clients:
    default: { host: localhost,port: 9200 }
indexes:
    websITe:
        client: default
        tyPEs:
            user:
                mappings:
                    username: { boost: 5 }
                    FirstName: { boost: 3 }
                persistence:
                    driver: orm # orm,mongodb,PRopel are available
                    model: Application\UserBundle\Entity\User
                    provider:

然后,您可以搜索这样的索引:

$userType = $this->container->get('foq_elastica.index.website.user');

$resultSet = $userType->search('bob');

但是,如果您想使用单个函数搜索多个实体,该怎么办?就像是…

配置:

foq_elastica:
clients:
    default: { host: localhost,port: 9200 }
indexes:
    website:
        client: default
        types:
            user:
                mappings:
                    username: { boost: 5 }
                    firstName: { boost: 3 }
                persistence:
                    driver: orm
                    model: Application\UserBundle\Entity\User
                    provider:
            client:
                mappings:
                    clientname: { boost: 5 }
                persistence:
                    driver: orm 
                    model: Application\UserBundle\Entity\Client
                    provider:

搜索功能

$Type = $this->container->get(['foq_elastica.index.website.user','foq_elastica.index.website.client']);

$resultSet = $Type->search('bob');

上面的代码不起作用,但我想知道是否有这样的方式在多个实体上进行单一搜索并根据其boost属性获得结果?

解决方法

在我看来,有两种方法可以做你想要的.您可以为User和Client创建父实体,并将其作为类型添加到索引中.只要看看Doctrine的 Inheritance Mapping;然而,我不确定FOQ_ElasticaBundle在索引中持久保存这些实体时是否以及如何处理这些实体.这只是方向指针,我不确定这是否会起作用!

我建议采用以下方法搜索索引而不是类型.您可以使用foq_elastica.index_manager来检索所需的索引(网站),然后构建一个使用类型过滤器将结果限制为用户和客户端类型的查询.

脚本宝典总结

以上是脚本宝典为你收集整理的php – Symfony 2 FOQElasticaBundle搜索多个实体全部内容,希望文章能够帮你解决php – Symfony 2 FOQElasticaBundle搜索多个实体所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。