Added hash: support to post searching

This commit is contained in:
Marcin Kurczewski 2014-09-30 14:52:02 +02:00
parent 6f563e72c3
commit 81c2025203
3 changed files with 51 additions and 36 deletions

1
TODO
View file

@ -20,7 +20,6 @@ everything related to posts:
- tag_count:3..5 - tag_count:3..5
- file_size:3K..5M - file_size:3K..5M
- image_size:huge/large/medium/small - image_size:huge/large/medium/small
- hash:postName
- type:img/flash/yt/video - type:img/flash/yt/video
- special:liked - special:liked
- special:disliked - special:disliked

View file

@ -9,4 +9,5 @@ class PostFilter extends BasicFilter implements IFilter
const REQUIREMENT_TAG = 'tag'; const REQUIREMENT_TAG = 'tag';
const REQUIREMENT_ID = 'id'; const REQUIREMENT_ID = 'id';
const REQUIREMENT_DATE = 'uploadTime'; const REQUIREMENT_DATE = 'uploadTime';
const REQUIREMENT_HASH = 'name';
} }

View file

@ -20,6 +20,30 @@ class PostSearchParser extends AbstractSearchParser
protected function decorateFilterFromNamedToken($filter, $token) protected function decorateFilterFromNamedToken($filter, $token)
{ {
if ($token->getKey() === 'id') if ($token->getKey() === 'id')
$this->addIdRequirement($filter, $token);
elseif ($token->getKey() === 'hash')
$this->addHashRequirement($filter, $token);
elseif ($token->getKey() === 'date')
$this->addDateRequirement($filter, $token);
else
throw new \BadMethodCallException('Not supported');
}
protected function getOrderColumn($token)
{
if ($token === 'fav_time')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FAV_TIME;
elseif ($token === 'fav_count')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FAV_COUNT;
throw new \BadMethodCallException('Not supported');
}
private function addIdRequirement($filter, $token)
{ {
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); $requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_ID); $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_ID);
@ -28,7 +52,15 @@ class PostSearchParser extends AbstractSearchParser
$filter->addRequirement($requirement); $filter->addRequirement($requirement);
} }
elseif ($token->getKey() === 'date') 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) if (substr_count($token->getValue(), '..') === 1)
{ {
@ -56,23 +88,6 @@ class PostSearchParser extends AbstractSearchParser
$filter->addRequirement($requirement); $filter->addRequirement($requirement);
} }
else
{
throw new \BadMethodCallException('Not supported');
}
}
protected function getOrderColumn($token)
{
if ($token === 'fav_time')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FAV_TIME;
elseif ($token === 'fav_count')
return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FAV_COUNT;
throw new \BadMethodCallException('Not supported');
}
private function dateToTime($value) private function dateToTime($value)
{ {
$value = strtolower(trim($value)); $value = strtolower(trim($value));