Fixed negative order in searches

This commit is contained in:
Marcin Kurczewski 2014-12-26 09:48:04 +01:00
parent 0945ed64ee
commit eb77b6811a

View file

@ -17,7 +17,7 @@ abstract class AbstractSearchParser
public function createFilterFromInputReader(InputReader $inputReader)
{
$filter = $this->createFilter();
$filter->setOrder($this->getOrder($inputReader->order) + $filter->getOrder());
$filter->setOrder($this->getOrder($inputReader->order, false) + $filter->getOrder());
if ($inputReader->page)
{
@ -32,7 +32,7 @@ abstract class AbstractSearchParser
if ($token instanceof NamedSearchToken)
{
if ($token->getKey() === 'order')
$filter->setOrder($this->getOrder($token->getValue()) + $filter->getOrder());
$filter->setOrder($this->getOrder($token->getValue(), $token->isNegated()) + $filter->getOrder());
else
$this->decorateFilterFromNamedToken($filter, $token);
}
@ -95,7 +95,7 @@ abstract class AbstractSearchParser
$filter->addRequirement($requirement);
}
private function getOrder($query)
private function getOrder($query, $negated)
{
$order = [];
$tokens = array_filter(preg_split('/\s+/', trim($query)));
@ -125,6 +125,12 @@ abstract class AbstractSearchParser
if ($orderColumn === null)
throw new \InvalidArgumentException('Invalid search order token: ' . $orderToken);
if ($negated)
{
$orderDir = $orderDir == IFilter::ORDER_DESC ? IFilter::ORDER_ASC : IFilter::ORDER_DESC;
}
$order[$orderColumn] = $orderDir;
}