make post search work exactly the same as comment search to

- stop confusing ppl
- future-proof for when posts eventually get too many to search
master
Aevann 2024-11-13 15:10:34 +02:00
parent dfd996a37c
commit d7a63f8cbd
2 changed files with 11 additions and 8 deletions

View File

@ -69,6 +69,10 @@ class Post(Base):
sharpened = Column(Boolean, default=False)
ping_cost = Column(Integer, default=0)
bump_utc = Column(Integer)
title_ts = Column(TSVECTOR(), server_default=FetchedValue())
body_ts = Column(TSVECTOR(), server_default=FetchedValue())
url_ts = Column(TSVECTOR(), server_default=FetchedValue())
embed_ts = Column(TSVECTOR(), server_default=FetchedValue())
if FEATURES['NSFW_MARKING']:
nsfw = Column(Boolean, default=False)

View File

@ -100,17 +100,16 @@ def searchposts(v):
posts = posts.filter(Post.author_id == author.id)
if 'q' in criteria:
params = [Post.title]
text = criteria['full_text']
params = [Post.title_ts]
if 'title_only' not in criteria:
params += [Post.body, Post.url, Post.embed]
params += [Post.body_ts, Post.url_ts, Post.embed_ts]
words = []
for x in criteria['q']:
for param in params:
if x.startswith('"') and x.endswith('"'):
words.append(param.regexp_match(f'[[:<:]]{x[1:-1]}[[:>:]]'))
else:
words.append(param.ilike(f'%{x}%'))
for param in params:
words.append(param.bool_op("@@")(func.websearch_to_tsquery("simple", text)))
posts = posts.filter(or_(*words))
if 'nsfw' in criteria: