From bdee75fd78f5752a6f3d88461ac1a21a7856ee64 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 30 Nov 2018 17:48:59 -0300 Subject: [PATCH] guilds: use patterns for messages.content in search --- litecord/blueprints/guilds.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/litecord/blueprints/guilds.py b/litecord/blueprints/guilds.py index a7e8a50..203e28f 100644 --- a/litecord/blueprints/guilds.py +++ b/litecord/blueprints/guilds.py @@ -291,15 +291,17 @@ async def search_messages(guild_id): # main message ids # TODO: filter only channels where user can # read messages to prevent leaking + rows = await app.db.fetch(f""" SELECT messages.id, COUNT(*) OVER() as total_results FROM messages WHERE guild_id = $1 + AND messages.content LIKE '%'||$2||'%' ORDER BY messages.id DESC LIMIT 50 - OFFSET $2 - """, guild_id, j['offset']) + OFFSET $3 + """, guild_id, j['content'], j['offset']) results = 0 if not rows else rows[0]['total_results'] main_messages = [r['id'] for r in rows]