我開始使用Symfony 2處理彈性搜索包,並對實體的搜索功能提出疑問。Symfony 2在多個實體上搜索FOQElasticaBundle
如果你有一個這樣的配置:
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');
上面的代碼不工作,但我不知道是否有這樣的一個方式做單搜索多個實體並根據其增強屬性獲取結果?
謝謝你的回覆,我採用了第二種方法,但我不確定你是否按照你的意思去做,我會用我的解決方案編輯我的帖子。 – CedricD