Added helluva search aliases
This commit is contained in:
parent
77983d8e20
commit
b7e2c28780
4 changed files with 103 additions and 81 deletions
|
@ -164,4 +164,20 @@ abstract class AbstractSearchParser
|
||||||
|
|
||||||
return $searchTokens;
|
return $searchTokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function matches($text, $array)
|
||||||
|
{
|
||||||
|
$transform = function($text)
|
||||||
|
{
|
||||||
|
return str_replace('_', '', strtolower($text));
|
||||||
|
};
|
||||||
|
|
||||||
|
$text = $transform($text);
|
||||||
|
foreach ($array as $elem)
|
||||||
|
{
|
||||||
|
if ($transform($elem) == $text)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,104 +40,113 @@ class PostSearchParser extends AbstractSearchParser
|
||||||
|
|
||||||
protected function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $token)
|
protected function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $token)
|
||||||
{
|
{
|
||||||
if ($token->getKey() === 'id')
|
$tokenKey = $token->getKey();
|
||||||
$this->addIdRequirement($filter, $token);
|
$tokenValue = $token->getValue();
|
||||||
|
|
||||||
elseif ($token->getKey() === 'hash')
|
if ($this->matches($tokenKey, ['tag_min', 'tag_max', 'fav_min', 'fav_max', 'score_min', 'score_max']))
|
||||||
$this->addHashRequirement($filter, $token);
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'date')
|
|
||||||
$this->addDateRequirement($filter, $token);
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'tag_count')
|
|
||||||
$this->addTagCountRequirement($filter, $token);
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'fav_count')
|
|
||||||
$this->addFavCountRequirement($filter, $token);
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'comment_count')
|
|
||||||
$this->addCommentCountRequirement($filter, $token);
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'score')
|
|
||||||
$this->addScoreRequirement($filter, $token);
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'uploader')
|
|
||||||
$this->addUploaderRequirement($filter, $token);
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'safety')
|
|
||||||
$this->addSafetyRequirement($filter, $token);
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'fav')
|
|
||||||
$this->addFavRequirement($filter, $token);
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'type')
|
|
||||||
$this->addTypeRequirement($filter, $token);
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'comment')
|
|
||||||
$this->addCommentRequirement($filter, $token);
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'special' && $token->getValue() === 'liked')
|
|
||||||
{
|
{
|
||||||
$this->privilegeService->assertLoggedIn();
|
|
||||||
$this->addUserScoreRequirement($filter, $this->authService->getLoggedInUser()->getName(), 1, $token->isNegated());
|
|
||||||
}
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'special' && $token->getValue() === 'disliked')
|
|
||||||
{
|
|
||||||
$this->privilegeService->assertLoggedIn();
|
|
||||||
$this->addUserScoreRequirement($filter, $this->authService->getLoggedInUser()->getName(), -1, $token->isNegated());
|
|
||||||
}
|
|
||||||
|
|
||||||
elseif ($token->getKey() === 'special' && $token->getValue() === 'fav')
|
|
||||||
{
|
|
||||||
$this->privilegeService->assertLoggedIn();
|
|
||||||
$token = new NamedSearchToken();
|
$token = new NamedSearchToken();
|
||||||
$token->setKey('fav');
|
$token->setKey(str_replace('__', '_', str_replace(['min', 'max'], '_count', $tokenKey)));
|
||||||
$token->setValue($this->authService->getLoggedInUser()->getName());
|
$token->setValue(strpos($tokenKey, 'min') !== false ? $tokenValue . '..' : '..' . $tokenValue);
|
||||||
$this->decorateFilterFromNamedToken($filter, $token);
|
return $this->decorateFilterFromNamedToken($filter, $token);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
$map =
|
||||||
throw new NotSupportedException();
|
[
|
||||||
|
[['id'], [$this, 'addIdRequirement']],
|
||||||
|
[['hash', 'name'], [$this, 'addHashRequirement']],
|
||||||
|
[['date', 'time'], [$this, 'addDateRequirement']],
|
||||||
|
[['tag_count'], [$this, 'addTagCountRequirement']],
|
||||||
|
[['fav_count'], [$this, 'addFavCountRequirement']],
|
||||||
|
[['comment_count'], [$this, 'addCommentCountRequirement']],
|
||||||
|
[['score'], [$this, 'addScoreRequirement']],
|
||||||
|
[['uploader', 'submit', 'up'], [$this, 'addUploaderRequirement']],
|
||||||
|
[['safety', 'rating'], [$this, 'addSafetyRequirement']],
|
||||||
|
[['fav'], [$this, 'addFavRequirement']],
|
||||||
|
[['type'], [$this, 'addTypeRequirement']],
|
||||||
|
[['comment'], [$this, 'addCommentRequirement']],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($map as $item)
|
||||||
|
{
|
||||||
|
list ($aliases, $callback) = $item;
|
||||||
|
if ($this->matches($tokenKey, $aliases))
|
||||||
|
{
|
||||||
|
return $callback($filter, $token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->matches($tokenKey, ['special']))
|
||||||
|
{
|
||||||
|
if ($this->matches($tokenValue, ['liked']))
|
||||||
|
{
|
||||||
|
$this->privilegeService->assertLoggedIn();
|
||||||
|
return $this->addUserScoreRequirement(
|
||||||
|
$filter,
|
||||||
|
$this->authService->getLoggedInUser()->getName(),
|
||||||
|
1,
|
||||||
|
$token->isNegated());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->matches($tokenValue, ['disliked']))
|
||||||
|
{
|
||||||
|
$this->privilegeService->assertLoggedIn();
|
||||||
|
return $this->addUserScoreRequirement(
|
||||||
|
$filter,
|
||||||
|
$this->authService->getLoggedInUser()->getName(),
|
||||||
|
-1,
|
||||||
|
$token->isNegated());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->matches($tokenValue, ['fav']))
|
||||||
|
{
|
||||||
|
$this->privilegeService->assertLoggedIn();
|
||||||
|
$token = new NamedSearchToken();
|
||||||
|
$token->setKey('fav');
|
||||||
|
$token->setValue($this->authService->getLoggedInUser()->getName());
|
||||||
|
return $this->decorateFilterFromNamedToken($filter, $token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOrderColumn($tokenText)
|
protected function getOrderColumn($tokenText)
|
||||||
{
|
{
|
||||||
if ($tokenText === 'random')
|
if ($this->matches($tokenText, ['random']))
|
||||||
return PostFilter::ORDER_RANDOM;
|
return PostFilter::ORDER_RANDOM;
|
||||||
|
|
||||||
elseif ($tokenText === 'id')
|
if ($this->matches($tokenText, ['id']))
|
||||||
return PostFilter::ORDER_ID;
|
return PostFilter::ORDER_ID;
|
||||||
|
|
||||||
elseif ($tokenText === 'time' || $tokenText === 'date')
|
if ($this->matches($tokenText, ['time', 'date']))
|
||||||
return PostFilter::ORDER_LAST_EDIT_TIME;
|
return PostFilter::ORDER_LAST_EDIT_TIME;
|
||||||
|
|
||||||
elseif ($tokenText === 'score')
|
if ($this->matches($tokenText, ['score']))
|
||||||
return PostFilter::ORDER_SCORE;
|
return PostFilter::ORDER_SCORE;
|
||||||
|
|
||||||
elseif ($tokenText === 'file_size')
|
if ($this->matches($tokenText, ['file_size']))
|
||||||
return PostFilter::ORDER_FILE_SIZE;
|
return PostFilter::ORDER_FILE_SIZE;
|
||||||
|
|
||||||
elseif ($tokenText === 'tag_count')
|
if ($this->matches($tokenText, ['tag_count', 'tags', 'tag']))
|
||||||
return PostFilter::ORDER_TAG_COUNT;
|
return PostFilter::ORDER_TAG_COUNT;
|
||||||
|
|
||||||
elseif ($tokenText === 'fav_count')
|
if ($this->matches($tokenText, ['fav_count', 'fags', 'fav']))
|
||||||
return PostFilter::ORDER_FAV_COUNT;
|
return PostFilter::ORDER_FAV_COUNT;
|
||||||
|
|
||||||
elseif ($tokenText === 'comment_count')
|
if ($this->matches($tokenText, ['comment_count', 'comments', 'comment']))
|
||||||
return PostFilter::ORDER_COMMENT_COUNT;
|
return PostFilter::ORDER_COMMENT_COUNT;
|
||||||
|
|
||||||
elseif ($tokenText === 'fav_time' || $tokenText === 'fav_date')
|
if ($this->matches($tokenText, ['fav_time', 'fav_date']))
|
||||||
return PostFilter::ORDER_LAST_FAV_TIME;
|
return PostFilter::ORDER_LAST_FAV_TIME;
|
||||||
|
|
||||||
elseif ($tokenText === 'comment_time' || $tokenText === 'comment_date')
|
if ($this->matches($tokenText, ['comment_time', 'comment_date']))
|
||||||
return PostFilter::ORDER_LAST_COMMENT_TIME;
|
return PostFilter::ORDER_LAST_COMMENT_TIME;
|
||||||
|
|
||||||
elseif ($tokenText === 'feature_time' || $tokenText === 'feature_date')
|
if ($this->matches($tokenText, ['feature_time', 'feature_date', 'featured', 'feature']))
|
||||||
return PostFilter::ORDER_LAST_FEATURE_TIME;
|
return PostFilter::ORDER_LAST_FEATURE_TIME;
|
||||||
|
|
||||||
else
|
throw new NotSupportedException();
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addIdRequirement($filter, $token)
|
private function addIdRequirement($filter, $token)
|
||||||
|
|
|
@ -26,34 +26,32 @@ class TagSearchParser extends AbstractSearchParser
|
||||||
|
|
||||||
protected function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $namedToken)
|
protected function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $namedToken)
|
||||||
{
|
{
|
||||||
if ($namedToken->getKey() === 'category')
|
if ($this->matches($namedToken->getKey(), ['category']))
|
||||||
{
|
{
|
||||||
$this->addRequirementFromToken(
|
return $this->addRequirementFromToken(
|
||||||
$filter,
|
$filter,
|
||||||
$namedToken,
|
$namedToken,
|
||||||
TagFilter::REQUIREMENT_CATEGORY,
|
TagFilter::REQUIREMENT_CATEGORY,
|
||||||
self::ALLOW_COMPOSITE);
|
self::ALLOW_COMPOSITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
throw new NotSupportedException();
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOrderColumn($tokenText)
|
protected function getOrderColumn($tokenText)
|
||||||
{
|
{
|
||||||
if ($tokenText === 'id')
|
if ($this->matches($tokenText, ['id']))
|
||||||
return TagFilter::ORDER_ID;
|
return TagFilter::ORDER_ID;
|
||||||
|
|
||||||
elseif ($tokenText === 'name')
|
if ($this->matches($tokenText, ['name']))
|
||||||
return TagFilter::ORDER_NAME;
|
return TagFilter::ORDER_NAME;
|
||||||
|
|
||||||
elseif ($tokenText === 'creation_time' || $tokenText === 'creation_date')
|
if ($this->matches($tokenText, ['creation_time', 'creation_date']))
|
||||||
return TagFilter::ORDER_CREATION_TIME;
|
return TagFilter::ORDER_CREATION_TIME;
|
||||||
|
|
||||||
elseif ($tokenText === 'usage_count')
|
if ($this->matches($tokenText, ['usage_count', 'usages']))
|
||||||
return TagFilter::ORDER_USAGE_COUNT;
|
return TagFilter::ORDER_USAGE_COUNT;
|
||||||
|
|
||||||
else
|
throw new NotSupportedException();
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,12 @@ class UserSearchParser extends AbstractSearchParser
|
||||||
|
|
||||||
protected function getOrderColumn($tokenText)
|
protected function getOrderColumn($tokenText)
|
||||||
{
|
{
|
||||||
if ($tokenText === 'name')
|
if ($this->matches($tokenText, ['name']))
|
||||||
return UserFilter::ORDER_NAME;
|
return UserFilter::ORDER_NAME;
|
||||||
|
|
||||||
elseif ($tokenText === 'registration_time' || $tokenText === 'registration_date')
|
if ($this->matches($tokenText, ['registration_time', 'registration_date']))
|
||||||
return UserFilter::ORDER_REGISTRATION_TIME;
|
return UserFilter::ORDER_REGISTRATION_TIME;
|
||||||
|
|
||||||
else
|
throw new NotSupportedException();
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue