created:1/1/2017 now matches objects created on that day
import re
import operator
-from datetime import datetime
+from datetime import datetime, timedelta
from haystack.query import SQ
from django.conf import settings
@@ -238,9 +238,16 @@ class ParseSQ(object):
# Parse date in one of a limited number of common formats.
# TODO: SOLR requires GMT; convert from GMT to local locale for date.
if search_field in self.DATE_FIELDS:
- datetime_object = parse_date(word)
- date = datetime_object.strftime("%Y-%m-%dT%H:%M:%SZ")
- self.sq = self.apply_operand(SQ(**{search_field+inequality_operator: date}))
+ thisday_object = parse_date(word)
+ thisday = thisday_object.strftime("%Y-%m-%dT%H:%M:%SZ")
+ if inequality_operator:
+ self.sq = self.apply_operand(SQ(**{search_field+inequality_operator: thisday}))
+ else:
+ # limit creation date to one day by generating two inequalities
+ nextday_object = thisday_object + timedelta(days=1)
+ nextday = nextday_object.strftime("%Y-%m-%dT%H:%M:%SZ")
+ self.sq = self.apply_operand(SQ(**{search_field+'__gte': thisday}) &
+ SQ(**{search_field+'__lt': nextday}))
else:
self.sq = self.apply_operand(SQ(**{search_field+inequality_operator: word}))
# remove unquoted text from query
