Exemple #1
0
def index():
    q = entities_query(request.args)
    q['size'] = get_limit(default=50)
    q['from'] = get_offset()
    doc_counts = arg_bool('doc_counts')
    res = execute_entities_query(request.args, q, doc_counts=doc_counts)
    return jsonify(res)
Exemple #2
0
def index():
    q = entities_query(request.args)
    q['size'] = get_limit(default=50)
    q['from'] = get_offset()
    doc_counts = arg_bool('doc_counts')
    res = execute_entities_query(request.args, q, doc_counts=doc_counts)
    return jsonify(res)
Exemple #3
0
def index():
    q = entities_query(request.args)
    q["size"] = get_limit(default=50)
    q["from"] = get_offset()
    doc_counts = arg_bool("doc_counts")
    res = execute_entities_query(request.args, q, doc_counts=doc_counts)
    return jsonify(res)
Exemple #4
0
def index():
    enable_cache(vary_user=True)
    results = [d for d in datasets if request.authz.check_roles(d.roles)]
    state = QueryState({
        'filter:dataset': [d.name for d in results],
        'facet': 'dataset',
        'limit': 0
    }, request.authz)
    res = entities_query(state)
    values = res.get('facets', {}).get('dataset', {}).get('values', [])
    counts = {v.get('id'): v.get('count') for v in values}

    countries_facet = defaultdict(int)
    category_facet = defaultdict(int)
    countries_filter = set(request.args.getlist('filter:countries'))
    category_filter = set(request.args.getlist('filter:category'))

    filtered = []
    for dataset in results:
        dataset.entities_count = counts.get(dataset.name)
        if len(category_filter) and dataset.category not in category_filter:
            continue
        if len(countries_filter) and \
           not len(countries_filter.intersection(dataset.countries)):
            continue
        for country in dataset.countries:
            countries_facet[country] += 1
        category_facet[dataset.category] += 1
        filtered.append(dataset)

    filtered = sorted(filtered, key=lambda d: d.entities_count, reverse=True)
    facets = {'countries': {'values': []}, 'category': {'values': []}}
    categories = get_config('COLLECTION_CATEGORIES', {})

    countries_facet = sorted(countries_facet.items(), key=lambda (k, c): c)
    for key, count in countries_facet[::-1]:
        facets['countries']['values'].append({
            'id': key,
            'count': count,
            'label': COUNTRY_NAMES.get(key, key)
        })

    category_facet = sorted(category_facet.items(), key=lambda (k, c): c)
    for key, count in category_facet[::-1]:
        if key is None:
            continue
        facets['category']['values'].append({
            'id': key,
            'count': count,
            'label': categories.get(key, key)
        })

    return jsonify({
        'results': filtered,
        'facets': facets,
        'total': len(filtered),
        'total_entities_count': res.get('total')
    })
Exemple #5
0
def statistics():
    enable_cache(vary_user=True)
    documents = documents_query(QueryState({}, request.authz, limit=0))
    entities = entities_query(QueryState({}, request.authz, limit=0))
    return jsonify({
        'documents_count': documents.get('total'),
        'entities_count': entities.get('total'),
        'collections_count': len(request.authz.collections_read)
    })
Exemple #6
0
def view(name):
    enable_cache(vary_user=True)
    try:
        dataset = datasets.get(name)
    except NameError:
        raise NotFound()
    request.authz.require(request.authz.check_roles(dataset.roles))
    state = QueryState({
        'filter:dataset': dataset.name,
        'facet': ['schema', 'countries'],
        'limit': 0
    }, request.authz)
    res = entities_query(state)
    data = dataset.to_dict()
    data['facets'] = res.get('facets', {})
    data['doc_count'] = res.get('total')
    return jsonify(data)
Exemple #7
0
def index():
    enable_cache(vary_user=True)
    state = QueryState(request.args, request.authz)
    doc_counts = state.getbool('doc_counts')
    res = entities_query(state, doc_counts=doc_counts)
    return jsonify(res)