diff --git a/TODO b/TODO index 5dc4e26b..949dcce1 100644 --- a/TODO +++ b/TODO @@ -20,7 +20,6 @@ everything related to posts: - tag_count:3..5 - file_size:3K..5M - image_size:huge/large/medium/small - - hash:postName - type:img/flash/yt/video - special:liked - special:disliked diff --git a/src/SearchServices/Filters/PostFilter.php b/src/SearchServices/Filters/PostFilter.php index da5216e8..9f9b62b4 100644 --- a/src/SearchServices/Filters/PostFilter.php +++ b/src/SearchServices/Filters/PostFilter.php @@ -9,4 +9,5 @@ class PostFilter extends BasicFilter implements IFilter const REQUIREMENT_TAG = 'tag'; const REQUIREMENT_ID = 'id'; const REQUIREMENT_DATE = 'uploadTime'; + const REQUIREMENT_HASH = 'name'; } diff --git a/src/SearchServices/Parsers/PostSearchParser.php b/src/SearchServices/Parsers/PostSearchParser.php index 00c44251..545cd76b 100644 --- a/src/SearchServices/Parsers/PostSearchParser.php +++ b/src/SearchServices/Parsers/PostSearchParser.php @@ -20,46 +20,16 @@ class PostSearchParser extends AbstractSearchParser protected function decorateFilterFromNamedToken($filter, $token) { if ($token->getKey() === 'id') - { - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_ID); - $requirement->setValue($this->createRequirementValue($token->getValue(), self::ALLOW_COMPOSITE | self::ALLOW_RANGES)); - $requirement->setNegated($token->isNegated()); - $filter->addRequirement($requirement); - } + $this->addIdRequirement($filter, $token); + + elseif ($token->getKey() === 'hash') + $this->addHashRequirement($filter, $token); elseif ($token->getKey() === 'date') - { - if (substr_count($token->getValue(), '..') === 1) - { - list ($dateMin, $dateMax) = explode('..', $token->getValue()); - $timeMin = $this->dateToTime($dateMin)[0]; - $timeMax = $this->dateToTime($dateMax)[1]; - } - else - { - $date = $token->getValue(); - list ($timeMin, $timeMax) = $this->dateToTime($date); - } - - $finalString = ''; - if ($timeMin) - $finalString .= date('c', $timeMin); - $finalString .= '..'; - if ($timeMax) - $finalString .= date('c', $timeMax); - - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_DATE); - $requirement->setValue($this->createRequirementValue($finalString, self::ALLOW_RANGES)); - $requirement->setNegated($token->isNegated()); - $filter->addRequirement($requirement); - } + $this->addDateRequirement($filter, $token); else - { throw new \BadMethodCallException('Not supported'); - } } protected function getOrderColumn($token) @@ -73,6 +43,51 @@ class PostSearchParser extends AbstractSearchParser throw new \BadMethodCallException('Not supported'); } + private function addIdRequirement($filter, $token) + { + $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); + $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_ID); + $requirement->setValue($this->createRequirementValue($token->getValue(), self::ALLOW_COMPOSITE | self::ALLOW_RANGES)); + $requirement->setNegated($token->isNegated()); + $filter->addRequirement($requirement); + } + + private function addHashRequirement($filter, $token) + { + $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); + $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_HASH); + $requirement->setValue($this->createRequirementValue($token->getValue(), self::ALLOW_COMPOSITE)); + $filter->addRequirement($requirement); + } + + private function addDateRequirement($filter, $token) + { + if (substr_count($token->getValue(), '..') === 1) + { + list ($dateMin, $dateMax) = explode('..', $token->getValue()); + $timeMin = $this->dateToTime($dateMin)[0]; + $timeMax = $this->dateToTime($dateMax)[1]; + } + else + { + $date = $token->getValue(); + list ($timeMin, $timeMax) = $this->dateToTime($date); + } + + $finalString = ''; + if ($timeMin) + $finalString .= date('c', $timeMin); + $finalString .= '..'; + if ($timeMax) + $finalString .= date('c', $timeMax); + + $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); + $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_DATE); + $requirement->setValue($this->createRequirementValue($finalString, self::ALLOW_RANGES)); + $requirement->setNegated($token->isNegated()); + $filter->addRequirement($requirement); + } + private function dateToTime($value) { $value = strtolower(trim($value));