Skip to content
Snippets Groups Projects
Sorting.php 514 B
Newer Older
Pavel's avatar
Pavel committed
<?php

Pavel's avatar
Pavel committed
namespace IQDEV\ElasticSearch\Search;
Pavel's avatar
Pavel committed

use IQDEV\ElasticSearch\Esable;

class Sorting implements Esable
{
    public string $by;
    public string $direction;

    public function __construct(string $by = '', string $direction = 'asc')
    {
        $this->by = $by;
        $this->direction = $direction;
    }

    public function es(): array
    {
        $sorting = [];

        if ($this->by) {
            $sorting['sort'] = [$this->by => $this->direction];
        }

        return $sorting;
    }
}