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,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));
|
||||
|
|
Loading…
Reference in a new issue