From a80050b70ec6761ccbba9fa0907a788b0b8e7ef2 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 30 Sep 2014 15:16:56 +0200 Subject: [PATCH] Added tag_count: support to post searching --- TODO | 1 - src/SearchServices/Filters/PostFilter.php | 1 + src/SearchServices/Parsers/PostSearchParser.php | 11 +++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index fc3fb5ed..9172f4fe 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,6 @@ everything related to posts: - fav:rr- - fav_count:3..5 - score:3..5 - - tag_count:3..5 - file_size:3K..5M - image_size:huge/large/medium/small - type:img/flash/yt/video diff --git a/src/SearchServices/Filters/PostFilter.php b/src/SearchServices/Filters/PostFilter.php index 269e96e7..941d674c 100644 --- a/src/SearchServices/Filters/PostFilter.php +++ b/src/SearchServices/Filters/PostFilter.php @@ -14,6 +14,7 @@ class PostFilter extends BasicFilter implements IFilter const REQUIREMENT_ID = 'id'; const REQUIREMENT_DATE = 'uploadTime'; const REQUIREMENT_HASH = 'name'; + const REQUIREMENT_TAG_COUNT = 'tagCount'; public function __construct() { diff --git a/src/SearchServices/Parsers/PostSearchParser.php b/src/SearchServices/Parsers/PostSearchParser.php index 80f3c6f8..ece6dbe1 100644 --- a/src/SearchServices/Parsers/PostSearchParser.php +++ b/src/SearchServices/Parsers/PostSearchParser.php @@ -28,6 +28,9 @@ class PostSearchParser extends AbstractSearchParser elseif ($token->getKey() === 'date') $this->addDateRequirement($filter, $token); + elseif ($token->getKey() === 'tag_count') + $this->addTagCountRequirement($filter, $token); + else throw new \BadMethodCallException('Not supported'); } @@ -100,6 +103,14 @@ class PostSearchParser extends AbstractSearchParser $filter->addRequirement($requirement); } + private function addTagCountRequirement($filter, $token) + { + $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); + $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TAG_COUNT); + $requirement->setValue($this->createRequirementValue($token->getValue(), self::ALLOW_COMPOSITE | self::ALLOW_RANGES)); + $filter->addRequirement($requirement); + } + private function dateToTime($value) { $value = strtolower(trim($value));