Skip to content
Snippets Groups Projects
Commit 345f8ae4 authored by Simonas Šerlinskas's avatar Simonas Šerlinskas
Browse files

Merge pull request #65 from mvar/fix_sort

Fix query sort structure
parents 1f9caebf ddacb5db
No related branches found
No related tags found
No related merge requests found
...@@ -125,15 +125,12 @@ class TopHitsAggregation extends AbstractAggregation ...@@ -125,15 +125,12 @@ class TopHitsAggregation extends AbstractAggregation
*/ */
public function getArray() public function getArray()
{ {
$output = $this->getSort() ? $this->getSort()->toArray() : [];
$output = array_filter( $output = array_filter(
array_merge( [
$output, 'sort' => $this->getSort() ? $this->getSort()->toArray() : null,
[ 'size' => $this->getSize(),
'size' => $this->getSize(), 'from' => $this->getFrom(),
'from' => $this->getFrom(), ],
]
),
function ($val) { function ($val) {
return (($val || is_array($val) || ($val || is_numeric($val)))); return (($val || is_array($val) || ($val || is_numeric($val))));
} }
......
...@@ -103,6 +103,6 @@ class FieldSort implements BuilderInterface ...@@ -103,6 +103,6 @@ class FieldSort implements BuilderInterface
$this->field => empty($fieldValues) ? new \stdClass() : $fieldValues, $this->field => empty($fieldValues) ? new \stdClass() : $fieldValues,
]; ];
return [$this->getType() => $output]; return $output;
} }
} }
...@@ -14,6 +14,7 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\DSL; ...@@ -14,6 +14,7 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\DSL;
use ONGR\ElasticsearchDSL\Query\MissingQuery; use ONGR\ElasticsearchDSL\Query\MissingQuery;
use ONGR\ElasticsearchDSL\Query\TermQuery; use ONGR\ElasticsearchDSL\Query\TermQuery;
use ONGR\ElasticsearchDSL\Search; use ONGR\ElasticsearchDSL\Search;
use ONGR\ElasticsearchDSL\Sort\FieldSort;
/** /**
* Test for Search. * Test for Search.
...@@ -242,6 +243,19 @@ class SearchTest extends \PHPUnit_Framework_TestCase ...@@ -242,6 +243,19 @@ class SearchTest extends \PHPUnit_Framework_TestCase
(new Search())->addQuery(new TermQuery('foo', 'bar'))->addFilter(new MissingQuery('baz')), (new Search())->addQuery(new TermQuery('foo', 'bar'))->addFilter(new MissingQuery('baz')),
]; ];
$cases['sort_by_price'] = [
[
'sort' => [
[
'price' => [
'order' => 'asc',
],
],
],
],
(new Search())->addSort(new FieldSort('price', 'asc')),
];
return $cases; return $cases;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment