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