From 3e33a40f7affc7fc524e7454bea9976186882a84 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 6 Aug 2020 13:56:36 -0700 Subject: better time ranges (don't search future) --- fatcat_scholar/search.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fatcat_scholar/search.py b/fatcat_scholar/search.py index d4736d1..7558db1 100644 --- a/fatcat_scholar/search.py +++ b/fatcat_scholar/search.py @@ -126,13 +126,16 @@ def do_fulltext_search( elif query.filter_time == "past_year": # (date in the past year) or (year is this year) # the later to catch papers which don't have release_date defined - year_ago_date = str(datetime.date.today() - datetime.timedelta(days=365)) - this_year = datetime.date.today().year + date_today = datetime.date.today() + this_year = date_today.year + tomorrow_date = str(date_today + datetime.timedelta(days=1)) + year_ago_date = str(date_today - datetime.timedelta(days=365)) search = search.filter( - Q("range", date=dict(gte=year_ago_date)) | Q("term", year=this_year) + Q("range", date=dict(gte=year_ago_date, lte=tomorrow_date)) | Q("term", year=this_year) ) elif query.filter_time == "since_2000": - search = search.filter("range", year=dict(gte=2000)) + this_year = datetime.date.today().year + search = search.filter("range", year=dict(gte=2000, lte=this_year)) elif query.filter_time == "before_1925": search = search.filter("range", year=dict(lt=1925)) elif query.filter_time == "all_time" or query.filter_time is None: -- cgit v1.2.3