Esempio n. 1
0
def suggest_entity():
    """Suggest API, emulates Google Refine API."""
    args = {
        'prefix': request.args.get('prefix'),
        'filter:schemata': request.args.getlist('type')
    }
    matches = []
    parser = SearchQueryParser(args, request.authz)
    if parser.prefix is not None:
        query = SuggestEntitiesQuery(parser)
        for doc in query.search().get('hits').get('hits'):
            source = doc.get('_source')
            match = {
                'quid': doc.get('_id'),
                'id': doc.get('_id'),
                'name': source.get('name'),
                'r:score': doc.get('_score'),
            }
            for type_ in get_freebase_types():
                if source.get('schema') == type_['id']:
                    match['n:type'] = type_
                    match['type'] = [type_['name']]
            matches.append(match)

    return jsonify({
        "code": "/api/status/ok",
        "status": "200 OK",
        "prefix": request.args.get('prefix', ''),
        "result": matches
    })
Esempio n. 2
0
def suggest():
    enable_cache()
    result = SuggestEntitiesQuery.handle(request, schema=CombinedSchema)
    return jsonify(result)