예제 #1
0
def all_get():
    # Get white list from URL, fallback to default if not present
    white_list = func.get_white_list(_default_white_list)

    # Get list of filters from elasticsearch
    known_filters = func.get_known_filters()

    # Return everything
    res = func.filter_response(
        white_list,
        known_filters,
        [],
        es.search(index=CONFIG.ES_INDEX, doc_type="item", size=CONFIG.MAX_QUERY_SIZE)['hits']['hits']
    )

    return func.respond(res)
예제 #2
0
def item_get(item_id):
    # Return singular item by id

    # Get whitelist
    white_list = func.get_white_list(_default_white_list)

    # Get known attributes
    known_filters = func.get_known_filters()

    # Get item
    res = func.filter_response(
        white_list,
        known_filters,
        [],
        es.get(index=CONFIG.ES_INDEX, doc_type="item", id=item_id)
    )

    return func.respond(res)
예제 #3
0
def search():
    # Query builder object
    qb = _default_es_query

    # Get white list from URL, fallback to default if not present
    white_list = func.get_white_list(_default_white_list)

    # If bounding box provided...
    bounding_coords = func.get_bounding_box_from_url()

    # Get accuracy mode
    high_accuracy = request.args.get('accuracy', 'low') == 'high'

    # If a bounding box is present and we are set to low accuracy, filter by it
    if None not in bounding_coords.values():
        func.filter_bounding_box(qb, bounding_coords)

    # Strip useless () from our filter string
    qs = json.dumps(qb).strip('()')

    # Get list of filters from elasticsearch
    known_filters = func.get_known_filters()

    # Get list of attribute filters from URL
    desired_filters = func.get_attribute_filters(known_filters)

    # Filter response
    res = func.filter_response(
        white_list,
        known_filters,
        desired_filters,
        es.search(
            index=CONFIG.ES_INDEX,
            doc_type="item",
            size=CONFIG.MAX_QUERY_SIZE,
            body=_es_match_all if high_accuracy or None in bounding_coords.values() else qs
        )['hits']['hits'],
        bounding_box=bounding_coords,
        high_accuracy=high_accuracy
    )

    # Return to user
    return func.respond(res)