quotes: add global searching

This commit is contained in:
jkhsjdhjs 2019-12-08 22:04:04 +00:00
parent db797b4fef
commit 84396cad99

View File

@ -90,7 +90,8 @@ class Quotes(DatabasePlugin):
else: else:
query = None query = None
index = args.get('<index>') index = args.get('<index>')
where = '' where = []
values = []
# search query support # search query support
if cmd or index and not is_int(index): if cmd or index and not is_int(index):
@ -113,11 +114,13 @@ class Quotes(DatabasePlugin):
else: else:
quote = ' '.join(quote) quote = ' '.join(quote)
values = [nick] if nick != 'search' or not query:
where.append('nick ILIKE %s')
values.append(nick)
if query: if query:
where.append('item ILIKE \'%%\' || %s || \'%%\'')
values.append(query) values.append(query)
where = 'AND item ILIKE \'%%\' || %s || \'%%\''
if index: if index:
index = parse_int(index) index = parse_int(index)
@ -148,14 +151,13 @@ class Quotes(DatabasePlugin):
FROM FROM
ranked_quotes ranked_quotes
WHERE WHERE
nick ILIKE %s
{where} {where}
ORDER BY ORDER BY
{order} {order}
LIMIT LIMIT
1 1
{offset} {offset}
'''.format(where=where, order=order, offset=offset), values) '''.format(where=' AND '.join(where), order=order, offset=offset), values)
result = self.cur.fetchone() result = self.cur.fetchone()
if result: if result: