Change from range only to before/after/between date(s)

git-svn-id: https://svn.eudat.eu/EUDAT/Services/MetaData/ckanext-datesearch@2718 68e52488-0a15-44bc-a314-416658652264
This commit is contained in:
Mikael Karlsson 2014-03-11 14:14:39 +00:00
parent f85a592b67
commit 738f9f4687
1 changed files with 9 additions and 6 deletions

View File

@ -27,16 +27,19 @@ class DateSearchPlugin(plugins.SingletonPlugin):
end_date = extras.get('ext_enddate')
log.debug("end_date: {0}".format(end_date))
if not start_date or not end_date:
# The user didn't select a start and end date, so do nothing.
if not start_date and not end_date:
# The user didn't select either a start and/or end date, so do nothing.
return search_params
if not start_date:
start_date = '*'
if not end_date:
end_date = '*'
# Add a date-range query with the selected start and end dates into the
# Solr facet queries.
# Add a date-range query with the selected start and/or end dates into the Solr facet queries.
fq = search_params['fq']
log.debug("fq: {0}".format(fq))
fq = '{fq} +metadata_modified:[{start_date} TO {end_date}]'.format(
fq=fq, start_date=start_date, end_date=end_date)
fq = '{fq} +metadata_modified:[{sd} TO {ed}]'.format(fq=fq, sd=start_date, ed=end_date)
log.debug("fq: {0}".format(fq))
search_params['fq'] = fq
log.debug("search_params: {0}".format(search_params))