微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐