server/search: support 'submit:' for anon uploads
This commit is contained in:
parent
d5e197e6ea
commit
61d084cc66
2 changed files with 22 additions and 6 deletions
|
@ -62,6 +62,22 @@ def _create_score_filter(score):
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def _create_user_filter():
|
||||||
|
def wrapper(query, criterion, negated):
|
||||||
|
if isinstance(criterion, criteria.PlainCriterion) \
|
||||||
|
and not criterion.value:
|
||||||
|
expr = db.Post.user_id == None # sic
|
||||||
|
if negated:
|
||||||
|
expr = ~expr
|
||||||
|
return query.filter(expr)
|
||||||
|
return search_util.create_subquery_filter(
|
||||||
|
db.Post.user_id,
|
||||||
|
db.User.user_id,
|
||||||
|
db.User.name,
|
||||||
|
search_util.create_str_filter)(query, criterion, negated)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class PostSearchConfig(BaseSearchConfig):
|
class PostSearchConfig(BaseSearchConfig):
|
||||||
def on_search_query_parsed(self, search_query):
|
def on_search_query_parsed(self, search_query):
|
||||||
new_special_tokens = []
|
new_special_tokens = []
|
||||||
|
@ -138,11 +154,7 @@ class PostSearchConfig(BaseSearchConfig):
|
||||||
lambda subquery: subquery.join(db.Tag).join(db.TagName)),
|
lambda subquery: subquery.join(db.Tag).join(db.TagName)),
|
||||||
'score': search_util.create_num_filter(db.Post.score),
|
'score': search_util.create_num_filter(db.Post.score),
|
||||||
('uploader', 'upload', 'submit'):
|
('uploader', 'upload', 'submit'):
|
||||||
search_util.create_subquery_filter(
|
_create_user_filter(),
|
||||||
db.Post.user_id,
|
|
||||||
db.User.user_id,
|
|
||||||
db.User.name,
|
|
||||||
search_util.create_str_filter),
|
|
||||||
'comment': search_util.create_subquery_filter(
|
'comment': search_util.create_subquery_filter(
|
||||||
db.Post.post_id,
|
db.Post.post_id,
|
||||||
db.Comment.post_id,
|
db.Comment.post_id,
|
||||||
|
|
|
@ -131,12 +131,15 @@ def test_filter_by_score(
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('input,expected_post_ids', [
|
@pytest.mark.parametrize('input,expected_post_ids', [
|
||||||
|
('uploader:', [4]),
|
||||||
('uploader:u1', [1]),
|
('uploader:u1', [1]),
|
||||||
('uploader:u3', [3]),
|
('uploader:u3', [3]),
|
||||||
('uploader:u1,u3', [1, 3]),
|
('uploader:u1,u3', [1, 3]),
|
||||||
|
('upload:', [4]),
|
||||||
('upload:u1', [1]),
|
('upload:u1', [1]),
|
||||||
('upload:u3', [3]),
|
('upload:u3', [3]),
|
||||||
('upload:u1,u3', [1, 3]),
|
('upload:u1,u3', [1, 3]),
|
||||||
|
('submit:', [4]),
|
||||||
('submit:u1', [1]),
|
('submit:u1', [1]),
|
||||||
('submit:u3', [3]),
|
('submit:u3', [3]),
|
||||||
('submit:u1,u3', [1, 3]),
|
('submit:u1,u3', [1, 3]),
|
||||||
|
@ -146,10 +149,11 @@ def test_filter_by_uploader(
|
||||||
post1 = post_factory(id=1)
|
post1 = post_factory(id=1)
|
||||||
post2 = post_factory(id=2)
|
post2 = post_factory(id=2)
|
||||||
post3 = post_factory(id=3)
|
post3 = post_factory(id=3)
|
||||||
|
post4 = post_factory(id=4)
|
||||||
post1.user = user_factory(name='u1')
|
post1.user = user_factory(name='u1')
|
||||||
post2.user = user_factory(name='u2')
|
post2.user = user_factory(name='u2')
|
||||||
post3.user = user_factory(name='u3')
|
post3.user = user_factory(name='u3')
|
||||||
db.session.add_all([post1, post2, post3])
|
db.session.add_all([post1, post2, post3, post4])
|
||||||
verify_unpaged(input, expected_post_ids)
|
verify_unpaged(input, expected_post_ids)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue