Skip to content
Snippets Groups Projects
Commit b9b558ed authored by Simonas Šerlinskas's avatar Simonas Šerlinskas Committed by GitHub
Browse files

Merge pull request #96 from einorler/issue79

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