如何使用symfony2上的elasticsearch进行方面查询?
我可以查询,并得到结果,它有效!
现在在此查询上,我想谈谈结果。
最佳答案
public function facetAction()
{
// index
$search = $this->get('fos_elastica.index.appellations.appellation');
$query = new \Elastica\Query\MatchAll();
$elasticaQuery = new \Elastica\Query();
$elasticaQuery->setQuery($query);
$elasticaQuery->setSize(550);
$elasticaFacet = new \Elastica\Facet\Terms('regions');
$elasticaFacet->setField('regions');
$elasticaFacet->setSize(550);
$elasticaFacet->setOrder('reverse_count');
$elasticaQuery->addFacet($elasticaFacet);
// ResultSet
$elasticaResultSet = $search->search($elasticaQuery);
// Get Facets
$elasticaFacets = $elasticaResultSet->getFacets();
foreach ($elasticaFacets['regions']['terms'] as $elasticaFacet) {
$results[] = $elasticaFacet;
}
return $this->container->get('templating')->renderResponse
('ApplicationGhvAppellationsBundle:Default:indexFacets.html.twig', array(
'appellations' => $results
));
}
关于symfony - 如何在symfony2上进行构面:FOSElasticaBundle?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16107605/