From b1ae13ab0aa81148eae2d83426d74fe7c0036f21 Mon Sep 17 00:00:00 2001 From: Agate Date: Thu, 27 Aug 2020 11:31:13 +0200 Subject: [PATCH] Fixed full-text search --- api/funkwhale_api/common/search.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api/funkwhale_api/common/search.py b/api/funkwhale_api/common/search.py index 06f2d02a2..5daa03abb 100644 --- a/api/funkwhale_api/common/search.py +++ b/api/funkwhale_api/common/search.py @@ -59,13 +59,19 @@ def get_query(query_string, search_fields): return query +def remove_chars(string, chars): + for char in chars: + string = string.replace(char, "") + return string + + def get_fts_query(query_string, fts_fields=["body_text"], model=None): - search_type = "plain" + search_type = "raw" if query_string.startswith('"') and query_string.endswith('"'): # we pass the query directly to the FTS engine query_string = query_string[1:-1] - search_type = "raw" else: + query_string = remove_chars(query_string, ['"', "&", "(", ")", "!", "'"]) parts = query_string.replace(":", "").split(" ") parts = ["{}:*".format(p) for p in parts if p] if not parts: