expand post searching to include bodies (instead of titles only)

master
Aevann1 2022-06-13 19:33:20 +02:00
parent 53a8818f80
commit 74a5ea88ac
1 changed files with 3 additions and 3 deletions

View File

@ -89,8 +89,8 @@ def searchposts(v):
if 'q' in criteria: if 'q' in criteria:
words=criteria['q'].split() words=criteria['q'].split()
words = criteria['q'].replace('\\', '').replace('_', '\_').replace('%', '\%').strip().split() words = criteria['q'].replace('\\', '').replace('_', '\_').replace('%', '\%').strip().split()
words=[Submission.title.ilike('%'+x+'%') for x in words] words = [or_(Submission.title.ilike('%'+x+'%'), Submission.body.ilike('%'+x+'%')) for x in words]
posts=posts.filter(*words) posts = posts.filter(*words)
if 'over18' in criteria: posts = posts.filter(Submission.over_18==True) if 'over18' in criteria: posts = posts.filter(Submission.over_18==True)
@ -287,4 +287,4 @@ def searchusers(v):
users=users[:25] users=users[:25]
if request.headers.get("Authorization"): return {"data": [x.json for x in users]} if request.headers.get("Authorization"): return {"data": [x.json for x in users]}
return render_template("search_users.html", v=v, query=query, total=total, page=page, users=users, sort=sort, t=t, next_exists=next_exists) return render_template("search_users.html", v=v, query=query, total=total, page=page, users=users, sort=sort, t=t, next_exists=next_exists)