From eb77b6811a0469db921d02d0d0aa7b4e658bcb0d Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 26 Dec 2014 09:48:04 +0100 Subject: [PATCH] Fixed negative order in searches --- src/Search/Parsers/AbstractSearchParser.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Search/Parsers/AbstractSearchParser.php b/src/Search/Parsers/AbstractSearchParser.php index 394c8f4b..3a859403 100644 --- a/src/Search/Parsers/AbstractSearchParser.php +++ b/src/Search/Parsers/AbstractSearchParser.php @@ -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; }