Reputation: 11
I use FOSElasticaBundle in my project to search a list of ads. I can get all the result but I can't order it in "asc" or "desc". I have seen different tutorial speaking about Filtering. But it's not working.
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();
I can't get where the problem is!
Upvotes: 1
Views: 527
Reputation: 4012
You did in a mistake in your code (parse error + bad construction of the JSON syntax):
$elasticaQuery->addSort(array('date' => 'desc'));
Upvotes: 1