From 38a386d5ae711ddd5a0269b9867fd4af2505f876 Mon Sep 17 00:00:00 2001 From: jonaswinkler <17569239+jonaswinkler@users.noreply.github.com> Date: Sat, 3 Apr 2021 21:02:13 +0200 Subject: [PATCH] fix date filtering for full text search --- src/documents/index.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/documents/index.py b/src/documents/index.py index a75534514..ec8057403 100644 --- a/src/documents/index.py +++ b/src/documents/index.py @@ -3,6 +3,7 @@ import os from contextlib import contextmanager import math +from dateutil.parser import isoparse from django.conf import settings from whoosh import highlight, classify, query from whoosh.fields import Schema, TEXT, NUMERIC, KEYWORD, DATETIME, BOOLEAN @@ -174,13 +175,17 @@ class DelayedQuery: elif k == 'document_type__isnull': criterias.append(query.Term("has_type", v == "false")) elif k == 'created__date__lt': - pass + criterias.append( + query.DateRange("created", start=None, end=isoparse(v))) elif k == 'created__date__gt': - pass + criterias.append( + query.DateRange("created", start=isoparse(v), end=None)) elif k == 'added__date__gt': - pass + criterias.append( + query.DateRange("added", start=isoparse(v), end=None)) elif k == 'added__date__lt': - pass + criterias.append( + query.DateRange("added", start=None, end=isoparse(v))) if len(criterias) > 0: return query.And(criterias) else: