Support has:* searches on the back end.

(imported from commit a6a6f465ce0343d4a5313ee54f6ff427940a03ab)
This commit is contained in:
Steve Howell 2014-03-05 12:41:01 -05:00
parent 25a9eae74b
commit 82a935080d
2 changed files with 16 additions and 0 deletions

View File

@ -96,6 +96,15 @@ class NarrowBuilderTest(AuthedTestCase):
term = dict(operator='search', operand='"french fries"')
check(term, 'WHERE (lower(content) LIKE lower(:content_1) OR lower(subject) LIKE lower(:subject_1)) AND (search_tsvector @@ plainto_tsquery(:param_2, :param_3))')
term = dict(operator='has', operand='attachment')
check(term, 'WHERE has_attachment')
term = dict(operator='has', operand='image')
check(term, 'WHERE has_image')
term = dict(operator='has', operand='link')
check(term, 'WHERE has_link')
class IncludeHistoryTest(AuthedTestCase):
def test_ok_to_include_history(self):
realm = get_realm('zulip.com')

View File

@ -111,6 +111,13 @@ class NarrowBuilder(object):
return method(query, operand, maybe_negate)
def by_has(self, query, operand, maybe_negate):
if operand not in ['attachment', 'image', 'link']:
raise BadNarrowOperator("unknown 'has' operand " + operand)
col_name = 'has_' + operand
cond = column(col_name)
return query.where(maybe_negate(cond))
def by_is(self, query, operand, maybe_negate):
if operand == 'private':
query = query.select_from(join(query.froms[0], "zerver_recipient",