Added score: support to post searching
This commit is contained in:
parent
47081293ef
commit
11931075f5
4 changed files with 48 additions and 23 deletions
1
TODO
1
TODO
|
@ -15,7 +15,6 @@ everything related to posts:
|
||||||
- comment:rr-
|
- comment:rr-
|
||||||
- comment_count: 3..5
|
- comment_count: 3..5
|
||||||
- fav:rr-
|
- fav:rr-
|
||||||
- score:3..5
|
|
||||||
- file_size:3K..5M
|
- file_size:3K..5M
|
||||||
- image_size:huge/large/medium/small
|
- image_size:huge/large/medium/small
|
||||||
- type:img/flash/yt/video
|
- type:img/flash/yt/video
|
||||||
|
|
|
@ -16,6 +16,7 @@ class PostFilter extends BasicFilter implements IFilter
|
||||||
const REQUIREMENT_HASH = 'name';
|
const REQUIREMENT_HASH = 'name';
|
||||||
const REQUIREMENT_TAG_COUNT = 'tagCount';
|
const REQUIREMENT_TAG_COUNT = 'tagCount';
|
||||||
const REQUIREMENT_FAV_COUNT = 'favCount';
|
const REQUIREMENT_FAV_COUNT = 'favCount';
|
||||||
|
const REQUIREMENT_SCORE = 'score';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
@ -61,6 +61,15 @@ abstract class AbstractSearchParser
|
||||||
return new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($text);
|
return new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function addRequirementFromToken($filter, $token, $type, $flags)
|
||||||
|
{
|
||||||
|
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
||||||
|
$requirement->setType($type, $flags);
|
||||||
|
$requirement->setValue($this->createRequirementValue($token->getValue(), $flags));
|
||||||
|
$requirement->setNegated($token->isNegated());
|
||||||
|
$filter->addRequirement($requirement);
|
||||||
|
}
|
||||||
|
|
||||||
private function getOrder($query)
|
private function getOrder($query)
|
||||||
{
|
{
|
||||||
$order = [];
|
$order = [];
|
||||||
|
|
|
@ -34,6 +34,9 @@ class PostSearchParser extends AbstractSearchParser
|
||||||
elseif ($token->getKey() === 'fav_count')
|
elseif ($token->getKey() === 'fav_count')
|
||||||
$this->addFavCountRequirement($filter, $token);
|
$this->addFavCountRequirement($filter, $token);
|
||||||
|
|
||||||
|
elseif ($token->getKey() === 'score')
|
||||||
|
$this->addScoreRequirement($filter, $token);
|
||||||
|
|
||||||
else
|
else
|
||||||
throw new \BadMethodCallException('Not supported');
|
throw new \BadMethodCallException('Not supported');
|
||||||
}
|
}
|
||||||
|
@ -63,19 +66,20 @@ class PostSearchParser extends AbstractSearchParser
|
||||||
|
|
||||||
private function addIdRequirement($filter, $token)
|
private function addIdRequirement($filter, $token)
|
||||||
{
|
{
|
||||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
$this->addRequirementFromToken(
|
||||||
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_ID);
|
$filter,
|
||||||
$requirement->setValue($this->createRequirementValue($token->getValue(), self::ALLOW_COMPOSITE | self::ALLOW_RANGES));
|
$token,
|
||||||
$requirement->setNegated($token->isNegated());
|
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_ID,
|
||||||
$filter->addRequirement($requirement);
|
self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addHashRequirement($filter, $token)
|
private function addHashRequirement($filter, $token)
|
||||||
{
|
{
|
||||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
$this->addRequirementFromToken(
|
||||||
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_HASH);
|
$filter,
|
||||||
$requirement->setValue($this->createRequirementValue($token->getValue(), self::ALLOW_COMPOSITE));
|
$token,
|
||||||
$filter->addRequirement($requirement);
|
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_HASH,
|
||||||
|
self::ALLOW_COMPOSITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addDateRequirement($filter, $token)
|
private function addDateRequirement($filter, $token)
|
||||||
|
@ -99,27 +103,39 @@ class PostSearchParser extends AbstractSearchParser
|
||||||
if ($timeMax)
|
if ($timeMax)
|
||||||
$finalString .= date('c', $timeMax);
|
$finalString .= date('c', $timeMax);
|
||||||
|
|
||||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
$token->setValue($finalString);
|
||||||
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_DATE);
|
$this->addRequirementFromToken(
|
||||||
$requirement->setValue($this->createRequirementValue($finalString, self::ALLOW_RANGES));
|
$filter,
|
||||||
$requirement->setNegated($token->isNegated());
|
$token,
|
||||||
$filter->addRequirement($requirement);
|
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_DATE,
|
||||||
|
self::ALLOW_RANGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addTagCountRequirement($filter, $token)
|
private function addTagCountRequirement($filter, $token)
|
||||||
{
|
{
|
||||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
$this->addRequirementFromToken(
|
||||||
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TAG_COUNT);
|
$filter,
|
||||||
$requirement->setValue($this->createRequirementValue($token->getValue(), self::ALLOW_COMPOSITE | self::ALLOW_RANGES));
|
$token,
|
||||||
$filter->addRequirement($requirement);
|
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TAG_COUNT,
|
||||||
|
self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addFavCountRequirement($filter, $token)
|
private function addFavCountRequirement($filter, $token)
|
||||||
{
|
{
|
||||||
$requirement = new \Szurubooru\SearchServices\Requirements\Requirement();
|
$this->addRequirementFromToken(
|
||||||
$requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAV_COUNT);
|
$filter,
|
||||||
$requirement->setValue($this->createRequirementValue($token->getValue(), self::ALLOW_COMPOSITE | self::ALLOW_RANGES));
|
$token,
|
||||||
$filter->addRequirement($requirement);
|
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAV_COUNT,
|
||||||
|
self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addScoreRequirement($filter, $token)
|
||||||
|
{
|
||||||
|
$this->addRequirementFromToken(
|
||||||
|
$filter,
|
||||||
|
$token,
|
||||||
|
\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_SCORE,
|
||||||
|
self::ALLOW_COMPOSITE | self::ALLOW_RANGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function dateToTime($value)
|
private function dateToTime($value)
|
||||||
|
|
Loading…
Reference in a new issue