我正在将FOSElasticaBundle集成到Symfony 2.3项目中,我需要按价格属性对结果进行排序。
下面是我的代码:
$finder = $this->container->get('fos_elastica.finder.website.product');
$fieldTerms = new \Elastica\Query\Terms();
$fieldTerms->setTerms('taxon_ids', $taxon_ids_array);
$boolQuery->addMust($fieldTerms);
$resultSet = $finder->find($boolQuery);我怎么能做到这一点?
谢谢
发布于 2013-07-06 01:24:35
尝试创建一个\Elastica\Query对象,该对象也包含排序信息,然后将其发送到finder:
$finder = $this->container->get('fos_elastica.finder.website.product');
$fieldTerms = new \Elastica\Query\Terms();
$fieldTerms->setTerms('taxon_ids', $taxon_ids_array);
$boolQuery->addMust($fieldTerms);
$finalQuery = new \Elastica\Query($boolQuery);
$finalQuery->setSort(array('price' => array('order' => 'asc')));
$resultSet = $finder->find($finalQuery);看看at the elasticsearch docs on the sort parameter,看看如何正确地使用它。
注意:\Elastica\Query与\Elastica\Query\AbstractQuery有很大的不同,前者封装了可以发送到_search端点的所有内容(facet、排序、解释等)。AbstractQuery表示每个单独查询类型(范围、模糊、术语等)的基本类型。
https://stackoverflow.com/questions/17486974
复制相似问题