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 = EntitiesQuery(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 })
def suggest_entity(): """Suggest API, emulates Google Refine API.""" prefix = request.args.get('prefix', '') args = { 'prefix': prefix, 'filter:schemata': request.args.getlist('type'), 'filter:collection_id': request.args.getlist('filter:collection_id') } parser = SearchQueryParser(args, request.authz) query = EntitiesQuery(parser) result = query.search() matches = list(entity_matches(result)) return jsonify({ "code": "/api/status/ok", "status": "200 OK", "prefix": prefix, "result": matches })
def suggest_entity(): """Suggest API, emulates Google Refine API.""" prefix = request.args.get("prefix", "") tag_request(prefix=prefix) types = request.args.getlist("type") or Entity.THING args = { "prefix": prefix, "filter:schemata": types, "filter:collection_id": request.args.getlist("filter:collection_id"), } parser = SearchQueryParser(args, request.authz) query = EntitiesQuery(parser) result = query.search() matches = list(entity_matches(result)) return jsonify({ "code": "/api/status/ok", "status": "200 OK", "prefix": prefix, "result": matches, })
def suggest_entity(): """Suggest API, emulates Google Refine API.""" prefix = request.args.get('prefix', '') tag_request(prefix=prefix) types = request.args.getlist('type') or Entity.THING args = { 'prefix': prefix, 'filter:schemata': types, 'filter:collection_id': request.args.getlist('filter:collection_id') } parser = SearchQueryParser(args, request.authz) query = EntitiesQuery(parser) result = query.search() matches = list(entity_matches(result)) return jsonify({ "code": "/api/status/ok", "status": "200 OK", "prefix": prefix, "result": matches })