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
|
- 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
|
||||||
|
|
|
@ -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';
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,46 +20,16 @@ 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);
|
||||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
|
||||||
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_ID);
|
elseif ($token->getKey() === 'hash')
|
||||||
$requirement->setValue($this->createRequirementValue($token->getValue(), self::ALLOW_COMPOSITE | self::ALLOW_RANGES));
|
$this->addHashRequirement($filter, $token);
|
||||||
$requirement->setNegated($token->isNegated());
|
|
||||||
$filter->addRequirement($requirement);
|
|
||||||
}
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'date')
|
elseif ($token->getKey() === 'date')
|
||||||
{
|
$this->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);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
throw new \BadMethodCallException('Not supported');
|
throw new \BadMethodCallException('Not supported');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOrderColumn($token)
|
protected function getOrderColumn($token)
|
||||||
|
@ -73,6 +43,51 @@ class PostSearchParser extends AbstractSearchParser
|
||||||
throw new \BadMethodCallException('Not supported');
|
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)
|
private function dateToTime($value)
|
||||||
{
|
{
|
||||||
$value = strtolower(trim($value));
|
$value = strtolower(trim($value));
|
||||||
|
|
Loading…
Reference in a new issue