gpt4 book ai didi

php - Symfony 2 FOQElasticaBundle 搜索多个实体

转载 作者:可可西里 更新时间:2023-10-31 22:57:01 24 4
gpt4 key购买 nike

我开始用 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 属性获得结果?

最佳答案

OP 的回答

这是我的解决方案...我编辑了我的配置文件,使查找器位于我网站的根目录,如下所示:

foq_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
website:
client: default
finder:
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:

我这样称呼我的搜索...

$finder = $this->container->get('foq_elastica.finder.website');

$results = $finder->find('bob');

它将在我的用户和客户实体中搜索!

关于php - Symfony 2 FOQElasticaBundle 搜索多个实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12683670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com