Added hash: support to post searching
This commit is contained in:
parent
6f563e72c3
commit
81c2025203
3 changed files with 51 additions and 36 deletions
1
TODO
1
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
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
|
|
@ -20,6 +20,30 @@ class PostSearchParser extends AbstractSearchParser
|
|||
protected function decorateFilterFromNamedToken($filter, $token)
|
||||
{
|
||||
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->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_ID);
|
||||
|
@ -28,7 +52,15 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$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)
|
||||
{
|
||||
|
@ -56,23 +88,6 @@ class PostSearchParser extends AbstractSearchParser
|
|||
$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)
|
||||
{
|
||||
$value = strtolower(trim($value));
|
||||
|
|
Loading…
Reference in a new issue