try smth on rdrama

master
Aevann 2024-02-13 21:53:46 +02:00
parent 760b5ff2c9
commit f67fc3d98a
1 changed files with 7 additions and 9 deletions

View File

@ -227,15 +227,13 @@ def searchcomments(v):
else: comments = comments.filter(Comment.author_id == author.id)
if 'q' in criteria:
tokens = map(lambda x: search_regex_1.sub('', x), criteria['q'])
tokens = filter(lambda x: len(x) > 0, tokens)
tokens = map(lambda x: search_regex_2.sub("\\'", x), tokens)
tokens = map(lambda x: x.strip(), tokens)
tokens = map(lambda x: search_regex_3.sub(' <-> ', x), tokens)
comments = comments.filter(Comment.body_ts.match(
' & '.join(tokens),
postgresql_regconfig='english'))
if 'exact' in criteria and 'full_text' in criteria:
regex_str = '[[:<:]]'+criteria['full_text']+'[[:>:]]' # https://docs.oracle.com/cd/E17952_01/mysql-5.5-en/regexp.html "word boundaries"
words = [Comment.body.regexp_match(regex_str)]
comments = comments.filter(*words)
elif 'q' in criteria:
words = [Comment.body.ilike('%'+x+'%') for x in criteria['q']]
comments = comments.filter(*words)
if 'nsfw' in criteria: comments = comments.filter(Comment.nsfw == True)