From 1cb7b72d6244e5f90ff199510572c569e1e20226 Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 28 Feb 2024 22:06:41 +0200 Subject: [PATCH] much better way of fixing exact searching that doesn't break shit --- files/routes/search.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/files/routes/search.py b/files/routes/search.py index ba227c3d2..0c259c940 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -224,11 +224,17 @@ def searchcomments(v): if 'q' in criteria: text = criteria['full_text'] - comments = comments.filter( - Comment.body_ts.bool_op("@@")( - func.websearch_to_tsquery("english", text) + if text.startswith('"') and text.endswith('"'): + search_text = escape_for_search(text[1:-1]) + comments = comments.filter( + Comment.body.ilike(f'%{search_text}%') + ) + else: + comments = comments.filter( + Comment.body_ts.bool_op("@@")( + func.websearch_to_tsquery("english", text) + ) ) - ) if 'nsfw' in criteria: nsfw = criteria['nsfw'].lower().strip() == 'true' @@ -323,11 +329,17 @@ def searchmessages(v): if 'q' in criteria: text = criteria['full_text'] - comments = comments.filter( - Comment.body_ts.bool_op("@@")( - func.websearch_to_tsquery("english", text) + if text.startswith('"') and text.endswith('"'): + search_text = escape_for_search(text[1:-1]) + comments = comments.filter( + Comment.body.ilike(f'%{search_text}%') + ) + else: + comments = comments.filter( + Comment.body_ts.bool_op("@@")( + func.websearch_to_tsquery("english", text) + ) ) - ) comments = apply_time_filter(t, comments, Comment)