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