加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Symfony 2 FOQElasticaBundle搜索多个实体

发布时间:2020-12-13 17:21:26 所属栏目:PHP教程 来源:网络整理
导读:我开始使用Symfony 2搞乱Elastic Search Bundle并且对实体的搜索功能有疑问. 如果您有这样的配置: foq_elastica:clients: default: { host: localhost,port: 9200 }indexes: website: client: default types: user: mappings: username: { boost: 5 } first
我开始使用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: ApplicationUserBundleEntityUser
                    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: ApplicationUserBundleEntityUser
                    provider:
            client:
                mappings:
                    clientname: { boost: 5 }
                persistence:
                    driver: orm 
                    model: ApplicationUserBundleEntityClient
                    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来检索所需的索引(网站),然后构建一个使用类型过滤器将结果限制为用户和客户端类型的查询.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读