Added name: keyword in post search
This commit is contained in:
parent
e3617434e6
commit
174fd80a73
3 changed files with 30 additions and 1 deletions
|
@ -37,6 +37,7 @@ Command | Description
|
|||
[search]datemin:...[/search] | posted on `...` or later (format like in `date:`) | `date_min` |
|
||||
[search]datemax:...[/search] | posted on `...` or earlier (format like in `date:`) | `date_max` |
|
||||
[search]id:1,2,3[/search] | having specific post ID | `ids` |
|
||||
[search]name:...[/search] | having specific post name (hash in full URLs) | `names`, `hash`, `hashes` |
|
||||
[search]idmin:5[/search] | posts with ID greater than or equal to @5 | `id_min` |
|
||||
[search]idmax:5[/search] | posts with ID less than or equal to @5 | `id_max` |
|
||||
[search]type:img[/search] | only image posts | `type:image` |
|
||||
|
|
|
@ -75,6 +75,12 @@ class PostSearchParser extends AbstractSearchParser
|
|||
return Sql\InFunctor::fromArray('post.id', Sql\Binding::fromArray($ids));
|
||||
}
|
||||
|
||||
if (in_array($key, ['name', 'names', 'hash', 'hashes']))
|
||||
{
|
||||
$ids = preg_split('/[;,]/', $value);
|
||||
return Sql\InFunctor::fromArray('post.name', Sql\Binding::fromArray($ids));
|
||||
}
|
||||
|
||||
elseif (in_array($key, ['fav', 'favs', 'favd']))
|
||||
{
|
||||
$user = UserModel::getByName($value);
|
||||
|
|
|
@ -218,6 +218,28 @@ class ListPostsJobTest extends AbstractTest
|
|||
}
|
||||
}
|
||||
|
||||
public function testNames()
|
||||
{
|
||||
$this->grantAccess('listPosts');
|
||||
$posts = $this->postMocker->mockMultiple(3);
|
||||
|
||||
foreach (['hash', 'hashes', 'name', 'names'] as $alias)
|
||||
{
|
||||
$ret = $this->assert->doesNotThrow(function() use ($alias, $posts)
|
||||
{
|
||||
$query = sprintf('%s:9999,%s,%s',
|
||||
$alias,
|
||||
$posts[0]->getName(),
|
||||
$posts[2]->getName());
|
||||
return Api::run(new ListPostsJob(), [JobArgs::ARG_QUERY => $query]);
|
||||
});
|
||||
|
||||
$this->assert->areEqual(2, $ret->entityCount);
|
||||
$this->assert->areEqual($posts[2]->getId(), $ret->entities[0]->getId());
|
||||
$this->assert->areEqual($posts[0]->getId(), $ret->entities[1]->getId());
|
||||
}
|
||||
}
|
||||
|
||||
public function testFavs()
|
||||
{
|
||||
$this->grantAccess('listPosts');
|
||||
|
|
Loading…
Reference in a new issue