From 47081293efe05203d65b8f88d6e35f16dd00fcdb Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 30 Sep 2014 15:18:54 +0200 Subject: [PATCH] Added fav_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 9172f4fe..379047a2 100644 --- a/TODO +++ b/TODO @@ -15,7 +15,6 @@ everything related to posts: - comment:rr- - comment_count: 3..5 - fav:rr- - - fav_count:3..5 - score:3..5 - file_size:3K..5M - image_size:huge/large/medium/small diff --git a/src/SearchServices/Filters/PostFilter.php b/src/SearchServices/Filters/PostFilter.php index 941d674c..d7f8f1cb 100644 --- a/src/SearchServices/Filters/PostFilter.php +++ b/src/SearchServices/Filters/PostFilter.php @@ -15,6 +15,7 @@ class PostFilter extends BasicFilter implements IFilter const REQUIREMENT_DATE = 'uploadTime'; const REQUIREMENT_HASH = 'name'; const REQUIREMENT_TAG_COUNT = 'tagCount'; + const REQUIREMENT_FAV_COUNT = 'favCount'; public function __construct() { diff --git a/src/SearchServices/Parsers/PostSearchParser.php b/src/SearchServices/Parsers/PostSearchParser.php index ece6dbe1..f1812eac 100644 --- a/src/SearchServices/Parsers/PostSearchParser.php +++ b/src/SearchServices/Parsers/PostSearchParser.php @@ -31,6 +31,9 @@ class PostSearchParser extends AbstractSearchParser elseif ($token->getKey() === 'tag_count') $this->addTagCountRequirement($filter, $token); + elseif ($token->getKey() === 'fav_count') + $this->addFavCountRequirement($filter, $token); + else throw new \BadMethodCallException('Not supported'); } @@ -111,6 +114,14 @@ class PostSearchParser extends AbstractSearchParser $filter->addRequirement($requirement); } + private function addFavCountRequirement($filter, $token) + { + $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); + $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAV_COUNT); + $requirement->setValue($this->createRequirementValue($token->getValue(), self::ALLOW_COMPOSITE | self::ALLOW_RANGES)); + $filter->addRequirement($requirement); + } + private function dateToTime($value) { $value = strtolower(trim($value));