Php 无法按FOSElasticaBundle进行排序
我在我的项目中使用FOSElasticaBundle搜索广告列表。我可以得到所有结果,但我不能在“asc”或“desc”中排序。我看到过关于过滤的不同教程。但它不起作用Php 无法按FOSElasticaBundle进行排序,php,symfony,
elasticsearch,foselasticabundle,Php,Symfony,
elasticsearch,Foselasticabundle,我在我的项目中使用FOSElasticaBundle搜索广告列表。我可以得到所有结果,但我不能在“asc”或“desc”中排序。我看到过关于过滤的不同教程。但它不起作用 if (!empty($cati)) { $query = new \Elastica\Query\Bool(); if((!empty($cati)) && $cati!='1') { $query1 = new \Elastica\Query\Match();
if (!empty($cati)) {
$query = new \Elastica\Query\Bool();
if((!empty($cati)) && $cati!='1')
{
$query1 = new \Elastica\Query\Match();
$query1->setFieldQuery('post.cat_id', $cati);
$query->addMust($query1);
}
}
else {
$query = new \Elastica\Query\MatchAll();
}
$elasticaQuery = new \Elastica\Query();
$elasticaQuery->setQuery($query);
$elasticaQuery->setSize($nbPerPage);
$elasticaQuery->setFrom(($page - 1) * $nbPerPage);
$elasticaQuery->addSort(array('date', array("desc"));
$repistoryManager = $this->container->get('fos_elastica.manager');
$repistory = $repistoryManager->getRepository('AdsManagerBundle:Post');
$eq = new \Elastica\Query();
$eq->setQuery($query);
$finder = $this->container->get('fos_elastica.index.ads.post');
$elasticaResultSet = $finder->search($eq);
$ed = $elasticaResultSet->getResults();
我不知道问题出在哪里 您在代码中犯了一个错误(解析错误+JSON语法的错误构造):
我试过了。它在“asc”中工作。但是,不是在“描述”中。我不知道为什么。
$elasticaQuery->addSort(array('date' => 'desc'));