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来检索所需的索引(网站),然后构建一个使用类型过滤器将结果限制为用户和客户端类型的查询.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...