本文整理匯總了Python中openspending.lib.browser.Browser.get_facets方法的典型用法代碼示例。如果您正苦於以下問題:Python Browser.get_facets方法的具體用法?Python Browser.get_facets怎麽用?Python Browser.get_facets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類openspending.lib.browser.Browser
的用法示例。
在下文中一共展示了Browser.get_facets方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: search
# 需要導入模塊: from openspending.lib.browser import Browser [as 別名]
# 或者: from openspending.lib.browser.Browser import get_facets [as 別名]
def search(self):
parser = SearchParamParser(request.params)
params, errors = parser.parse()
if errors:
response.status = 400
return to_jsonp({'errors': errors})
expand_facets = params.pop('expand_facet_dimensions')
format = params.pop('format')
if format == 'csv':
params['stats'] = False
params['facet_field'] = None
datasets = params.pop('dataset', None)
if datasets is None or not datasets:
q = Dataset.all_by_account(c.account)
if params.get('category'):
q = q.filter_by(category=params.pop('category'))
datasets = q.all()
expand_facets = False
if not datasets:
return {'errors': ["No dataset available."]}
params['filter']['dataset'] = []
for dataset in datasets:
require.dataset.read(dataset)
params['filter']['dataset'].append(dataset.name)
response.last_modified = max([d.updated_at for d in datasets])
etag_cache_keygen(parser.key(), response.last_modified)
if params['pagesize'] > parser.defaults['pagesize']:
# http://wiki.nginx.org/X-accel#X-Accel-Buffering
response.headers['X-Accel-Buffering'] = 'no'
if format == 'csv':
csv_headers(response, 'entries.csv')
streamer = CSVStreamingResponse(
datasets,
params,
pagesize=parser.defaults['pagesize']
)
return streamer.response()
else:
json_headers(filename='entries.json')
streamer = JSONStreamingResponse(
datasets,
params,
pagesize=parser.defaults['pagesize'],
expand_facets=util.expand_facets
if expand_facets else None,
callback=request.params.get('callback')
)
return streamer.response()
solr_browser = Browser(**params)
try:
solr_browser.execute()
except SolrException as e:
return {'errors': [unicode(e)]}
entries = []
for dataset, entry in solr_browser.get_entries():
entry = entry_apply_links(dataset.name, entry)
entry['dataset'] = dataset_apply_links(dataset.as_dict())
entries.append(entry)
if format == 'csv':
return write_csv(entries, response,
filename='entries.csv')
if expand_facets and len(datasets) == 1:
facets = solr_browser.get_expanded_facets(datasets[0])
else:
facets = solr_browser.get_facets()
return to_jsonp({
'stats': solr_browser.get_stats(),
'facets': facets,
'results': entries
})