|
|
@@ -17,6 +17,10 @@
|
|
|
|
|
|
from __future__ import division
|
|
|
|
|
|
+from builtins import next
|
|
|
+from builtins import str
|
|
|
+from builtins import zip
|
|
|
+from builtins import object
|
|
|
import collections
|
|
|
import datetime
|
|
|
import dateutil
|
|
|
@@ -278,16 +282,16 @@ class Collection2(object):
|
|
|
try:
|
|
|
schema_fields = api.fields(name)
|
|
|
schema_fields = schema_fields['schema']['fields']
|
|
|
- except Exception, e:
|
|
|
+ except Exception as e:
|
|
|
LOG.warn('/luke call did not succeed: %s' % e)
|
|
|
try:
|
|
|
fields = api.schema_fields(name)
|
|
|
schema_fields = Collection2._make_luke_from_schema_fields(fields)
|
|
|
- except Exception, e:
|
|
|
+ except Exception as e:
|
|
|
LOG.error('Could not access collection: %s' % e)
|
|
|
return []
|
|
|
|
|
|
- return sorted([self._make_field(field, attributes) for field, attributes in schema_fields.iteritems()])
|
|
|
+ return sorted([self._make_field(field, attributes) for field, attributes in schema_fields.items()])
|
|
|
|
|
|
def update_data(self, post_data):
|
|
|
data_dict = self.data
|
|
|
@@ -327,7 +331,7 @@ def get_facet_field(category, field, facets):
|
|
|
else:
|
|
|
id_pattern = '%(field)s-%(id)s'
|
|
|
|
|
|
- facets = filter(lambda facet: facet['type'] == category and id_pattern % facet == field, facets)
|
|
|
+ facets = [facet for facet in facets if facet['type'] == category and id_pattern % facet == field]
|
|
|
|
|
|
if facets:
|
|
|
return facets[0]
|
|
|
@@ -490,7 +494,7 @@ def augment_solr_response(response, collection, query):
|
|
|
}
|
|
|
normalized_facets.append(facet)
|
|
|
elif category == 'query' and response['facet_counts']['facet_queries']:
|
|
|
- for name, value in response['facet_counts']['facet_queries'].iteritems():
|
|
|
+ for name, value in response['facet_counts']['facet_queries'].items():
|
|
|
collection_facet = get_facet_field(category, name, collection['facets'])
|
|
|
facet = {
|
|
|
'id': collection_facet['id'],
|
|
|
@@ -624,7 +628,7 @@ def augment_solr_response(response, collection, query):
|
|
|
_series[legend].append(row[prev_last_seen_dim_col_index])
|
|
|
_series[legend].append(cell)
|
|
|
|
|
|
- for _name, val in _series.iteritems():
|
|
|
+ for _name, val in _series.items():
|
|
|
_c = range_pair2(
|
|
|
facet['field'],
|
|
|
_name,
|
|
|
@@ -675,7 +679,7 @@ def augment_solr_response(response, collection, query):
|
|
|
counts = _augment_stats_2d(name, facet, counts, selected_values, agg_keys, rows)
|
|
|
actual_dimension = sum([_f['aggregate']['function'] == 'count' for _f in collection_facet['properties']['facets']])
|
|
|
|
|
|
- counts = filter(lambda a: len(a['fq_fields']) == actual_dimension, counts)
|
|
|
+ counts = [a for a in counts if len(a['fq_fields']) == actual_dimension]
|
|
|
|
|
|
num_bucket = response['facets'][name]['numBuckets'] if 'numBuckets' in response['facets'][name] else len(response['facets'][name])
|
|
|
facet = {
|
|
|
@@ -687,7 +691,7 @@ def augment_solr_response(response, collection, query):
|
|
|
'extraSeries': extraSeries,
|
|
|
'dimension': dimension,
|
|
|
'response': {'response': {'start': 0, 'numFound': num_bucket}}, # Todo * nested buckets + offsets
|
|
|
- 'docs': [dict(zip(cols, row)) for row in rows],
|
|
|
+ 'docs': [dict(list(zip(cols, row))) for row in rows],
|
|
|
'fieldsAttributes': [Collection2._make_gridlayout_header_field({'name': col, 'type': 'aggr' if '(' in col else 'string'}) for col in cols],
|
|
|
'multiselect': collection_facet['properties']['facets'][0].get('multiselect', True)
|
|
|
}
|
|
|
@@ -708,7 +712,7 @@ def augment_solr_response(response, collection, query):
|
|
|
|
|
|
def _get_agg_keys(counts):
|
|
|
for count in counts:
|
|
|
- keys = [key for key, value in count.items() if key.lower().startswith('agg_') or key.lower().startswith('dim_')]
|
|
|
+ keys = [key for key, value in list(count.items()) if key.lower().startswith('agg_') or key.lower().startswith('dim_')]
|
|
|
if keys:
|
|
|
return keys
|
|
|
return []
|
|
|
@@ -727,7 +731,7 @@ def augment_response(collection, query, response):
|
|
|
meta = {'type': 'link', 'link': doc['link']}
|
|
|
link = get_data_link(meta)
|
|
|
|
|
|
- for field, value in doc.iteritems():
|
|
|
+ for field, value in doc.items():
|
|
|
if isinstance(value, numbers.Number):
|
|
|
escaped_value = value
|
|
|
elif field == '_childDocuments_': # Nested documents
|
|
|
@@ -748,7 +752,7 @@ def augment_response(collection, query, response):
|
|
|
doc['numFound'] = _doc['numFound']
|
|
|
del response['moreLikeThis'][doc['hueId']]
|
|
|
|
|
|
- highlighted_fields = response.get('highlighting', {}).keys()
|
|
|
+ highlighted_fields = list(response.get('highlighting', {}).keys())
|
|
|
if highlighted_fields and not query.get('download'):
|
|
|
id_field = collection.get('idField')
|
|
|
if id_field:
|
|
|
@@ -758,7 +762,7 @@ def augment_response(collection, query, response):
|
|
|
|
|
|
if highlighting:
|
|
|
escaped_highlighting = {}
|
|
|
- for field, hls in highlighting.iteritems():
|
|
|
+ for field, hls in highlighting.items():
|
|
|
_hls = [escape(smart_unicode(hl, errors='replace')).replace('<em>', '<em>').replace('</em>', '</em>') for hl in hls]
|
|
|
escaped_highlighting[field] = _hls[0] if len(_hls) == 1 else _hls
|
|
|
|
|
|
@@ -843,7 +847,7 @@ def __augment_stats_2d(counts, label, fq_fields, fq_values, fq_filter, _selected
|
|
|
# List nested fields
|
|
|
_agg_keys = []
|
|
|
if agg_key in bucket and bucket[agg_key]['buckets']: # Protect against empty buckets
|
|
|
- for key, value in bucket[agg_key]['buckets'][0].items():
|
|
|
+ for key, value in list(bucket[agg_key]['buckets'][0].items()):
|
|
|
if key.lower().startswith('agg_') or key.lower().startswith('dim_'):
|
|
|
_agg_keys.append(key)
|
|
|
_agg_keys.sort(key=lambda a: a[4:])
|