Example #1
0
def load_data():
    """
    Load all table data into the search index.
    """
    try:
        loader.download()
        load_table_data()
        status = 'loaded'
    except Exception as ex:
        log.log_traceback(ex)
        status = 'failed'
    return flask.jsonify({'status': status})
Example #2
0
    q = args.get('q', '')
    table = args.get('table')
    filter_params = {'filter': args.get('filter')}
    try:
        total, result = db_client.search(table, q,
                                         limit, offset,
                                         **filter_params)
        data['result_count'] = total
        data['results'] = result
    except db.InvalidTable:
        data['error'] = 'Invalid table:'+str(table)

    return flask.jsonify(data)


def load_table_data():
    log.debug("Loading table data...")
    for table, data in loader.read():
        log.debug(table)
        db_client.load(table, data)
    db_client.data_loaded = True


if __name__ == '__main__':
    log.debug("Starting ...")
    db_client.connect()
    # Download data if we do not have it.
    loader.download(exists=False)
    load_table_data()
    app.run()