|
@@ -124,7 +124,7 @@ class SolrApi(object):
|
|
|
'mincount': int(facet['properties']['mincount'])
|
|
'mincount': int(facet['properties']['mincount'])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if timeFilter and timeFilter['time_field'] == facet['field'] and (facet['id'] not in timeFilter['time_filter_overrides'] or facet['widgetType'] != 'histogram-widget'):
|
|
|
|
|
|
|
+ if facet['properties']['canRange'] or timeFilter and timeFilter['time_field'] == facet['field'] and (facet['id'] not in timeFilter['time_filter_overrides'] or facet['widgetType'] != 'histogram-widget'):
|
|
|
keys.update(self._get_time_filter_query(timeFilter, facet))
|
|
keys.update(self._get_time_filter_query(timeFilter, facet))
|
|
|
|
|
|
|
|
params += (
|
|
params += (
|
|
@@ -145,7 +145,7 @@ class SolrApi(object):
|
|
|
elif facet['type'] == 'nested':
|
|
elif facet['type'] == 'nested':
|
|
|
_f = {}
|
|
_f = {}
|
|
|
if facet['properties']['facets']:
|
|
if facet['properties']['facets']:
|
|
|
- self._n_facet_dimension(facet, _f, facet['properties']['facets'], 1, timeFilter)
|
|
|
|
|
|
|
+ self._n_facet_dimension(facet, _f, facet['properties']['facets'], 1, timeFilter, can_range = facet['properties']['canRange'])
|
|
|
|
|
|
|
|
if facet['properties'].get('domain'):
|
|
if facet['properties'].get('domain'):
|
|
|
if facet['properties']['domain'].get('blockParent') or facet['properties']['domain'].get('blockChildren'):
|
|
if facet['properties']['domain'].get('blockParent') or facet['properties']['domain'].get('blockChildren'):
|
|
@@ -273,7 +273,7 @@ class SolrApi(object):
|
|
|
return self._get_json(response)
|
|
return self._get_json(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
- def _n_facet_dimension(self, widget, _f, facets, dim, timeFilter):
|
|
|
|
|
|
|
+ def _n_facet_dimension(self, widget, _f, facets, dim, timeFilter, can_range=None):
|
|
|
facet = facets[0]
|
|
facet = facets[0]
|
|
|
f_name = 'dim_%02d:%s' % (dim, facet['field'])
|
|
f_name = 'dim_%02d:%s' % (dim, facet['field'])
|
|
|
|
|
|
|
@@ -296,13 +296,14 @@ class SolrApi(object):
|
|
|
'type': 'terms',
|
|
'type': 'terms',
|
|
|
'field': '%(field)s' % facet,
|
|
'field': '%(field)s' % facet,
|
|
|
'limit': int(facet.get('limit', 10)),
|
|
'limit': int(facet.get('limit', 10)),
|
|
|
- 'mincount': int(facet['mincount']),
|
|
|
|
|
'numBuckets': True,
|
|
'numBuckets': True,
|
|
|
'allBuckets': True,
|
|
'allBuckets': True,
|
|
|
'sort': sort,
|
|
'sort': sort,
|
|
|
'missing': facet.get('missing', False)
|
|
'missing': facet.get('missing', False)
|
|
|
#'prefix': '' # Forbidden on numeric fields
|
|
#'prefix': '' # Forbidden on numeric fields
|
|
|
}
|
|
}
|
|
|
|
|
+ if int(facet['mincount']):
|
|
|
|
|
+ _f[f_name]['mincount'] = int(facet['mincount']) # Forbidden on n > 0 field if mincount = 0
|
|
|
|
|
|
|
|
if 'start' in facet and not facet.get('type') == 'field':
|
|
if 'start' in facet and not facet.get('type') == 'field':
|
|
|
_f[f_name].update({
|
|
_f[f_name].update({
|
|
@@ -313,7 +314,7 @@ class SolrApi(object):
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
# Only on dim 1 currently
|
|
# Only on dim 1 currently
|
|
|
- if timeFilter and timeFilter['time_field'] == facet['field'] and (widget['id'] not in timeFilter['time_filter_overrides']): # or facet['widgetType'] != 'bucket-widget'):
|
|
|
|
|
|
|
+ if can_range or (timeFilter and timeFilter['time_field'] == facet['field'] and (widget['id'] not in timeFilter['time_filter_overrides'])): # or facet['widgetType'] != 'bucket-widget'):
|
|
|
facet['widgetType'] = widget['widgetType']
|
|
facet['widgetType'] = widget['widgetType']
|
|
|
_f[f_name].update(self._get_time_filter_query(timeFilter, facet))
|
|
_f[f_name].update(self._get_time_filter_query(timeFilter, facet))
|
|
|
|
|
|
|
@@ -937,10 +938,19 @@ class SolrApi(object):
|
|
|
return props
|
|
return props
|
|
|
|
|
|
|
|
def _get_time_filter_query(self, timeFilter, facet):
|
|
def _get_time_filter_query(self, timeFilter, facet):
|
|
|
- if 'fixed' in timeFilter:
|
|
|
|
|
|
|
+ properties = facet.get('properties', facet)
|
|
|
|
|
+ if not timeFilter:
|
|
|
|
|
+ props = {}
|
|
|
|
|
+ stat_facet = {'min': properties['start'], 'max': properties['end']}
|
|
|
|
|
+ _compute_range_facet(facet['widgetType'], stat_facet, props, stat_facet['min'], stat_facet['max'],
|
|
|
|
|
+ SLOTS=properties['slot'])
|
|
|
|
|
+ return {
|
|
|
|
|
+ 'gap': '%(gap)s' % props, # add a 'auto'
|
|
|
|
|
+ }
|
|
|
|
|
+ elif 'fixed' in timeFilter or properties['slot'] != 0:
|
|
|
props = {}
|
|
props = {}
|
|
|
stat_facet = {'min': timeFilter['from'], 'max': timeFilter['to']}
|
|
stat_facet = {'min': timeFilter['from'], 'max': timeFilter['to']}
|
|
|
- _compute_range_facet(facet['widgetType'], stat_facet, props, stat_facet['min'], stat_facet['max'])
|
|
|
|
|
|
|
+ _compute_range_facet(facet['widgetType'], stat_facet, props, stat_facet['min'], stat_facet['max'], SLOTS = properties['slot'])
|
|
|
gap = props['gap']
|
|
gap = props['gap']
|
|
|
unit = re.split('\d+', gap)[1]
|
|
unit = re.split('\d+', gap)[1]
|
|
|
return {
|
|
return {
|
|
@@ -1074,6 +1084,7 @@ GAPS = {
|
|
|
'bucket-widget': {'coeff': '+3', 'unit': 'SECONDS'}, # ~100 slots
|
|
'bucket-widget': {'coeff': '+3', 'unit': 'SECONDS'}, # ~100 slots
|
|
|
'bar-widget': {'coeff': '+3', 'unit': 'SECONDS'}, # ~100 slots
|
|
'bar-widget': {'coeff': '+3', 'unit': 'SECONDS'}, # ~100 slots
|
|
|
'facet-widget': {'coeff': '+1', 'unit': 'MINUTES'}, # ~10 slots
|
|
'facet-widget': {'coeff': '+1', 'unit': 'MINUTES'}, # ~10 slots
|
|
|
|
|
+ 'pie-widget': {'coeff': '+1', 'unit': 'MINUTES'} # ~10 slots
|
|
|
},
|
|
},
|
|
|
'30MINUTES': {
|
|
'30MINUTES': {
|
|
|
'histogram-widget': {'coeff': '+20', 'unit': 'SECONDS'},
|
|
'histogram-widget': {'coeff': '+20', 'unit': 'SECONDS'},
|
|
@@ -1081,6 +1092,7 @@ GAPS = {
|
|
|
'bucket-widget': {'coeff': '+20', 'unit': 'SECONDS'},
|
|
'bucket-widget': {'coeff': '+20', 'unit': 'SECONDS'},
|
|
|
'bar-widget': {'coeff': '+20', 'unit': 'SECONDS'},
|
|
'bar-widget': {'coeff': '+20', 'unit': 'SECONDS'},
|
|
|
'facet-widget': {'coeff': '+5', 'unit': 'MINUTES'},
|
|
'facet-widget': {'coeff': '+5', 'unit': 'MINUTES'},
|
|
|
|
|
+ 'pie-widget': {'coeff': '+5', 'unit': 'MINUTES'},
|
|
|
},
|
|
},
|
|
|
'1HOURS': {
|
|
'1HOURS': {
|
|
|
'histogram-widget': {'coeff': '+30', 'unit': 'SECONDS'},
|
|
'histogram-widget': {'coeff': '+30', 'unit': 'SECONDS'},
|
|
@@ -1088,6 +1100,7 @@ GAPS = {
|
|
|
'bucket-widget': {'coeff': '+30', 'unit': 'SECONDS'},
|
|
'bucket-widget': {'coeff': '+30', 'unit': 'SECONDS'},
|
|
|
'bar-widget': {'coeff': '+30', 'unit': 'SECONDS'},
|
|
'bar-widget': {'coeff': '+30', 'unit': 'SECONDS'},
|
|
|
'facet-widget': {'coeff': '+10', 'unit': 'MINUTES'},
|
|
'facet-widget': {'coeff': '+10', 'unit': 'MINUTES'},
|
|
|
|
|
+ 'pie-widget': {'coeff': '+10', 'unit': 'MINUTES'}
|
|
|
},
|
|
},
|
|
|
'12HOURS': {
|
|
'12HOURS': {
|
|
|
'histogram-widget': {'coeff': '+7', 'unit': 'MINUTES'},
|
|
'histogram-widget': {'coeff': '+7', 'unit': 'MINUTES'},
|
|
@@ -1095,6 +1108,7 @@ GAPS = {
|
|
|
'bucket-widget': {'coeff': '+7', 'unit': 'MINUTES'},
|
|
'bucket-widget': {'coeff': '+7', 'unit': 'MINUTES'},
|
|
|
'bar-widget': {'coeff': '+7', 'unit': 'MINUTES'},
|
|
'bar-widget': {'coeff': '+7', 'unit': 'MINUTES'},
|
|
|
'facet-widget': {'coeff': '+1', 'unit': 'HOURS'},
|
|
'facet-widget': {'coeff': '+1', 'unit': 'HOURS'},
|
|
|
|
|
+ 'pie-widget': {'coeff': '+1', 'unit': 'HOURS'}
|
|
|
},
|
|
},
|
|
|
'1DAYS': {
|
|
'1DAYS': {
|
|
|
'histogram-widget': {'coeff': '+15', 'unit': 'MINUTES'},
|
|
'histogram-widget': {'coeff': '+15', 'unit': 'MINUTES'},
|
|
@@ -1102,6 +1116,7 @@ GAPS = {
|
|
|
'bucket-widget': {'coeff': '+15', 'unit': 'MINUTES'},
|
|
'bucket-widget': {'coeff': '+15', 'unit': 'MINUTES'},
|
|
|
'bar-widget': {'coeff': '+15', 'unit': 'MINUTES'},
|
|
'bar-widget': {'coeff': '+15', 'unit': 'MINUTES'},
|
|
|
'facet-widget': {'coeff': '+3', 'unit': 'HOURS'},
|
|
'facet-widget': {'coeff': '+3', 'unit': 'HOURS'},
|
|
|
|
|
+ 'pie-widget': {'coeff': '+3', 'unit': 'HOURS'}
|
|
|
},
|
|
},
|
|
|
'2DAYS': {
|
|
'2DAYS': {
|
|
|
'histogram-widget': {'coeff': '+30', 'unit': 'MINUTES'},
|
|
'histogram-widget': {'coeff': '+30', 'unit': 'MINUTES'},
|
|
@@ -1109,6 +1124,7 @@ GAPS = {
|
|
|
'bucket-widget': {'coeff': '+30', 'unit': 'MINUTES'},
|
|
'bucket-widget': {'coeff': '+30', 'unit': 'MINUTES'},
|
|
|
'bar-widget': {'coeff': '+30', 'unit': 'MINUTES'},
|
|
'bar-widget': {'coeff': '+30', 'unit': 'MINUTES'},
|
|
|
'facet-widget': {'coeff': '+6', 'unit': 'HOURS'},
|
|
'facet-widget': {'coeff': '+6', 'unit': 'HOURS'},
|
|
|
|
|
+ 'pie-widget': {'coeff': '+6', 'unit': 'HOURS'}
|
|
|
},
|
|
},
|
|
|
'7DAYS': {
|
|
'7DAYS': {
|
|
|
'histogram-widget': {'coeff': '+3', 'unit': 'HOURS'},
|
|
'histogram-widget': {'coeff': '+3', 'unit': 'HOURS'},
|
|
@@ -1116,6 +1132,7 @@ GAPS = {
|
|
|
'bucket-widget': {'coeff': '+3', 'unit': 'HOURS'},
|
|
'bucket-widget': {'coeff': '+3', 'unit': 'HOURS'},
|
|
|
'bar-widget': {'coeff': '+3', 'unit': 'HOURS'},
|
|
'bar-widget': {'coeff': '+3', 'unit': 'HOURS'},
|
|
|
'facet-widget': {'coeff': '+1', 'unit': 'DAYS'},
|
|
'facet-widget': {'coeff': '+1', 'unit': 'DAYS'},
|
|
|
|
|
+ 'pie-widget': {'coeff': '+1', 'unit': 'DAYS'}
|
|
|
},
|
|
},
|
|
|
'1MONTHS': {
|
|
'1MONTHS': {
|
|
|
'histogram-widget': {'coeff': '+12', 'unit': 'HOURS'},
|
|
'histogram-widget': {'coeff': '+12', 'unit': 'HOURS'},
|
|
@@ -1123,6 +1140,7 @@ GAPS = {
|
|
|
'bucket-widget': {'coeff': '+12', 'unit': 'HOURS'},
|
|
'bucket-widget': {'coeff': '+12', 'unit': 'HOURS'},
|
|
|
'bar-widget': {'coeff': '+12', 'unit': 'HOURS'},
|
|
'bar-widget': {'coeff': '+12', 'unit': 'HOURS'},
|
|
|
'facet-widget': {'coeff': '+5', 'unit': 'DAYS'},
|
|
'facet-widget': {'coeff': '+5', 'unit': 'DAYS'},
|
|
|
|
|
+ 'pie-widget': {'coeff': '+5', 'unit': 'DAYS'}
|
|
|
},
|
|
},
|
|
|
'3MONTHS': {
|
|
'3MONTHS': {
|
|
|
'histogram-widget': {'coeff': '+1', 'unit': 'DAYS'},
|
|
'histogram-widget': {'coeff': '+1', 'unit': 'DAYS'},
|
|
@@ -1130,6 +1148,7 @@ GAPS = {
|
|
|
'bucket-widget': {'coeff': '+1', 'unit': 'DAYS'},
|
|
'bucket-widget': {'coeff': '+1', 'unit': 'DAYS'},
|
|
|
'bar-widget': {'coeff': '+1', 'unit': 'DAYS'},
|
|
'bar-widget': {'coeff': '+1', 'unit': 'DAYS'},
|
|
|
'facet-widget': {'coeff': '+30', 'unit': 'DAYS'},
|
|
'facet-widget': {'coeff': '+30', 'unit': 'DAYS'},
|
|
|
|
|
+ 'pie-widget': {'coeff': '+30', 'unit': 'DAYS'}
|
|
|
},
|
|
},
|
|
|
'1YEARS': {
|
|
'1YEARS': {
|
|
|
'histogram-widget': {'coeff': '+3', 'unit': 'DAYS'},
|
|
'histogram-widget': {'coeff': '+3', 'unit': 'DAYS'},
|
|
@@ -1137,6 +1156,7 @@ GAPS = {
|
|
|
'bucket-widget': {'coeff': '+3', 'unit': 'DAYS'},
|
|
'bucket-widget': {'coeff': '+3', 'unit': 'DAYS'},
|
|
|
'bar-widget': {'coeff': '+3', 'unit': 'DAYS'},
|
|
'bar-widget': {'coeff': '+3', 'unit': 'DAYS'},
|
|
|
'facet-widget': {'coeff': '+12', 'unit': 'MONTHS'},
|
|
'facet-widget': {'coeff': '+12', 'unit': 'MONTHS'},
|
|
|
|
|
+ 'pie-widget': {'coeff': '+12', 'unit': 'MONTHS'}
|
|
|
},
|
|
},
|
|
|
'2YEARS': {
|
|
'2YEARS': {
|
|
|
'histogram-widget': {'coeff': '+7', 'unit': 'DAYS'},
|
|
'histogram-widget': {'coeff': '+7', 'unit': 'DAYS'},
|
|
@@ -1144,6 +1164,7 @@ GAPS = {
|
|
|
'bucket-widget': {'coeff': '+7', 'unit': 'DAYS'},
|
|
'bucket-widget': {'coeff': '+7', 'unit': 'DAYS'},
|
|
|
'bar-widget': {'coeff': '+7', 'unit': 'DAYS'},
|
|
'bar-widget': {'coeff': '+7', 'unit': 'DAYS'},
|
|
|
'facet-widget': {'coeff': '+3', 'unit': 'MONTHS'},
|
|
'facet-widget': {'coeff': '+3', 'unit': 'MONTHS'},
|
|
|
|
|
+ 'pie-widget': {'coeff': '+3', 'unit': 'MONTHS'}
|
|
|
},
|
|
},
|
|
|
'10YEARS': {
|
|
'10YEARS': {
|
|
|
'histogram-widget': {'coeff': '+1', 'unit': 'MONTHS'},
|
|
'histogram-widget': {'coeff': '+1', 'unit': 'MONTHS'},
|
|
@@ -1151,5 +1172,6 @@ GAPS = {
|
|
|
'bucket-widget': {'coeff': '+1', 'unit': 'MONTHS'},
|
|
'bucket-widget': {'coeff': '+1', 'unit': 'MONTHS'},
|
|
|
'bar-widget': {'coeff': '+1', 'unit': 'MONTHS'},
|
|
'bar-widget': {'coeff': '+1', 'unit': 'MONTHS'},
|
|
|
'facet-widget': {'coeff': '+1', 'unit': 'YEARS'},
|
|
'facet-widget': {'coeff': '+1', 'unit': 'YEARS'},
|
|
|
|
|
+ 'pie-widget': {'coeff': '+1', 'unit': 'YEARS'}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|