From 133508fc6a349aa7aef141cdffa5d8c41ca7dd88 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 15 Aug 2022 21:02:23 +0200 Subject: [PATCH] add "before" and "after" search keywords --- files/routes/search.py | 17 +++++++++++++++++ files/templates/search.html | 2 ++ 2 files changed, 19 insertions(+) diff --git a/files/routes/search.py b/files/routes/search.py index 3711f3e56..8f70983a2 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -13,6 +13,8 @@ valid_params = [ 'domain', 'over18', "post", + "before", + "after", search_operator_hole, ] @@ -116,6 +118,14 @@ def searchposts(v): if search_operator_hole in criteria: posts = posts.filter(Submission.sub == criteria[search_operator_hole]) + if 'after' in criteria: + after = int(criteria['after']) + posts = posts.filter(Submission.created_utc > after) + + if 'before' in criteria: + before = int(criteria['before']) + posts = posts.filter(Submission.created_utc < before) + posts = apply_time_filter(t, posts, Submission) posts = sort_posts(sort, posts) @@ -205,6 +215,13 @@ def searchcomments(v): club = [x[0] for x in g.db.query(Submission.id).filter(Submission.club == True).all()] comments = comments.filter(Comment.parent_submission.notin_(club)) + if 'after' in criteria: + after = int(criteria['after']) + comments = comments.filter(Comment.created_utc > after) + + if 'before' in criteria: + before = int(criteria['before']) + comments = comments.filter(Comment.created_utc < before) comments = sort_comments(sort, comments) diff --git a/files/templates/search.html b/files/templates/search.html index fdcf0af95..5ba32f7b5 100644 --- a/files/templates/search.html +++ b/files/templates/search.html @@ -86,6 +86,8 @@
  • domain:reddit.com
  • over18:true
  • {{HOLE_NAME}}:music
  • +
  • before:1660590018
  • +
  • after:1660590018
  • {% if request.path.startswith('/search/comments') %}
  • post:504
  • {% endif %}