Php 多实体上的Symfony 2 FoqElasticBundle搜索
我开始用Symfony 2处理弹性搜索包,对实体的搜索功能有疑问 如果您有这样的配置:Php 多实体上的Symfony 2 FoqElasticBundle搜索,php,symfony,elasticsearch,Php,Symfony,elasticsearch,我开始用Symfony 2处理弹性搜索包,对实体的搜索功能有疑问 如果您有这样的配置: foq_elastica: clients: default: { host: localhost, port: 9200 } indexes: website: client: default types: user: mappings: username: { b
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
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:
然后可以像这样搜索索引:
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
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:
但是如果你想用一个函数搜索多个实体呢?类似于
配置:
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属性获取结果?在我看来,有两种方法可以实现您的愿望。您可以为用户和客户端创建父实体,并将其作为类型添加到索引中。只要看一看教义;但是,我不确定FOQ_ElasticaBundle在索引中持久化这些实体时是否以及如何处理这些实体。这只是一个指向方向的指针,我不确定这是否有效
我建议使用以下方法:搜索索引而不是类型。您可以使用
foq\u elastica.index\u manager
检索您想要的索引(网站),然后构建一个查询,该查询使用类型筛选器将结果限制为您的用户和客户端类型。从OP中回答
这是我的解决方案…我编辑了配置文件,使查找程序位于我网站的根目录下,如下所示:
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
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');
它将在我的用户和客户端实体中搜索 谢谢你的回复,我同意你的第二种方法,但我不确定我的方式是否是你想要的方式,我将用我的解决方案编辑我的帖子。订购方式?我的意思是,如果elasticSearch检索这两个表中的随机结果,或者检索一个表中的第一个结果