Skip to content
Snippets Groups Projects
Commit b5492a93 authored by Mantas's avatar Mantas
Browse files

added parameter trait to FieldSort

parent 806267bc
No related branches found
No related tags found
No related merge requests found
......@@ -12,12 +12,15 @@
namespace ONGR\ElasticsearchDSL\Sort;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Holds all the values required for basic sorting.
*/
class FieldSort implements BuilderInterface
{
use ParametersTrait;
const ASC = 'asc';
const DESC = 'desc';
......@@ -31,11 +34,6 @@ class FieldSort implements BuilderInterface
*/
private $order;
/**
* @var array
*/
private $params;
/**
* @var BuilderInterface
*/
......@@ -50,7 +48,7 @@ class FieldSort implements BuilderInterface
{
$this->field = $field;
$this->order = $order;
$this->params = $params;
$this->setParameters($params);
}
/**
......@@ -85,22 +83,15 @@ class FieldSort implements BuilderInterface
public function toArray()
{
if ($this->order) {
$this->params['order'] = $this->order;
$this->addParameter('order', $this->order);
}
if ($this->nestedFilter) {
$fieldValues = array_merge(
$this->params,
[
'nested_filter' => $this->nestedFilter->toArray(),
]
);
} else {
$fieldValues = $this->params;
$this->addParameter('nested_filter', $this->nestedFilter->toArray());
}
$output = [
$this->field => empty($fieldValues) ? new \stdClass() : $fieldValues,
$this->field => !$this->getParameters() ? new \stdClass() : $this->getParameters(),
];
return $output;
......
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