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