我开始使用Symfony 2的Elastic Search Bundle,并对entities的搜索功能有一个问题。
如果你有这样的配置:
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属性获得结果?
发布于 2012-10-02 15:52:47
在我看来,有两种方法可以做你想做的事情。您可以为User和Client创建父实体,并将其作为类型添加到索引中。只要看看Doctrine的Inheritance Mapping就知道了;但是,我不确定Doctrine在将这些实体持久化到索引时是否以及如何处理这些实体。这只是一个方向的指针,我不确定这是否会工作!
我推荐以下方法:搜索索引而不是类型。您可以使用foq_elastica.index_manager来检索您想要的索引(网站),然后构建一个查询,该查询使用类型过滤器将结果限制为您的用户和客户端类型。
发布于 2012-10-12 23:52:46
来自OP的应答
这是我的解决方案……我编辑了我的配置文件,将finder放在我网站的根目录下,如下所示:
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');它将在我的用户和客户端实体中进行搜索!
https://stackoverflow.com/questions/12683670
复制相似问题