Skip to content

Commit

Permalink
[search] Disable date range guessing with dates older than 1900
Browse files Browse the repository at this point in the history
  • Loading branch information
romainr committed May 19, 2015
1 parent a5e197d commit 33893f3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apps/search/src/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def _guess_range_facet(widget_type, solr_api, collection, facet_field, propertie
start = re.sub('\.\d\d?\d?Z$', 'Z', start)
try:
start_ts = datetime.strptime(start, '%Y-%m-%dT%H:%M:%SZ')
start_ts.strftime('%Y-%m-%dT%H:%M:%SZ') # Check for dates before 1900
except Exception, e:
LOG.error('Bad date: %s' % e)
start_ts = datetime.strptime('1970-01-01T00:00:00Z', '%Y-%m-%dT%H:%M:%SZ')
Expand All @@ -90,6 +91,7 @@ def _guess_range_facet(widget_type, solr_api, collection, facet_field, propertie
end = re.sub('\.\d\d?\d?Z$', 'Z', end)
try:
end_ts = datetime.strptime(end, '%Y-%m-%dT%H:%M:%SZ')
end_ts.strftime('%Y-%m-%dT%H:%M:%SZ') # Check for dates before 1900
except Exception, e:
LOG.error('Bad date: %s' % e)
end_ts = datetime.strptime('2050-01-01T00:00:00Z', '%Y-%m-%dT%H:%M:%SZ')
Expand Down
3 changes: 2 additions & 1 deletion desktop/libs/libsolr/src/libsolr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ def _get_aggregate_function(self, facet):
'field': facet['field'],
'aggregate': facet['properties']['aggregate'] if 'properties' in facet else facet['aggregate']
}

if props['aggregate'] == 'median':
return 'percentile(%(field)s,50)' % props
else:
return '%(aggregate)s(%(field)s)' % props

props = {}
def _get_range_borders(self, collection, query):
props = {}
GAPS = {
Expand Down Expand Up @@ -598,6 +598,7 @@ def stats(self, core, fields, query=None, facet=''):

params += tuple([('stats.field', field) for field in fields])
response = self._root.get('%(core)s/select' % {'core': core}, params=params)

return self._get_json(response)
except RestException, e:
raise PopupException(e, title=_('Error while accessing Solr'))
Expand Down

0 comments on commit 33893f3

Please sign in to comment.