Skip to content
Snippets Groups Projects
Commit 41e190a2 authored by Mantas Jonušas's avatar Mantas Jonušas
Browse files

Changed getArray method in top hits aggregation

parent 893d4e47
No related branches found
No related tags found
No related merge requests found
......@@ -49,9 +49,7 @@ class TopHitsAggregation extends AbstractAggregation
parent::__construct($name);
$this->setFrom($from);
$this->setSize($size);
if (!empty($sort)) {
$this->setSort($sort);
}
$this->setSort($sort);
}
/**
......@@ -129,18 +127,32 @@ class TopHitsAggregation extends AbstractAggregation
{
$data = new \stdClass();
if ($this->getSort()) {
$data->sort = $this->getSort()->toArray();
}
if ($this->getSize()) {
$data->size = $this->getSize();
}
if ($this->getFrom()) {
$data->from = $this->getFrom();
$filteredData = $this->getFilteredData();
foreach ($filteredData as $key => $value) {
$data->{$key} = $value;
}
return $data;
}
/**
* Filters the data.
*
* @return array
*/
private function getFilteredData()
{
$fd = array_filter(
[
'sort' => $this->getSort() ? $this->getSort()->toArray() : [],
'size' => $this->getSize(),
'from' => $this->getFrom(),
],
function ($val) {
return (($val || is_array($val) || ($val || is_numeric($val))));
}
);
return $fd;
}
}
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