def _build_query_raw(request): query = {} params = {} if request.method == 'GET': for k, v in request.args.iteritems(): _update_query_raw(query, params, k, v) if 'query' not in query: query['query'] = {'match_all': {}} elif request.method == 'POST': try: query = json.loads(request.json or request.data or request.form.keys()[0]) except (ValueError, IndexError): return {'error': 'Could not parse request payload!', 'status': 400}, None params = request.args for o in (params, query): if 'from' in o: o['from'] = max(0, atoi(o['from'])) if 'size' in o: o['size'] = min(RESULTS_MAX_SIZE, max(0, atoi(o['size']))) return query, params
def search_annotations(): params = dict(request.args.items()) kwargs = dict() # Take limit and offset out of the parameters if 'offset' in params: kwargs['offset'] = atoi(params.pop('offset'), default=None) if 'limit' in params: kwargs['limit'] = atoi(params.pop('limit'), default=None) if 'sort' in params: kwargs['sort'] = params.pop('sort') if 'order' in params: kwargs['order'] = params.pop('order') # All remaining parameters are considered searched fields. kwargs['query'] = params if current_app.config.get('AUTHZ_ON'): # Pass the current user to do permission filtering on results kwargs['user'] = g.user results = g.annotation_class.search(**kwargs) total = g.annotation_class.count(**kwargs) return jsonify({'total': total, 'rows': results})
def _build_query_raw(request): query = {} params = {} if request.method == 'GET': for k, v in iteritems(request.args): _update_query_raw(query, params, k, v) if 'query' not in query: query['query'] = {'match_all': {}} elif request.method == 'POST': try: query = json.loads(request.json or request.data or request.form.keys()[0]) except (ValueError, IndexError): raise ValueError params = request.args for o in (params, query): if 'from' in o: o['from'] = max(0, atoi(o['from'])) if 'size' in o: o['size'] = min(RESULTS_MAX_SIZE, max(0, atoi(o['size']))) return query, params
def _build_query_raw(request): query = {} params = {} if request.method == "GET": for k, v in iteritems(request.args): _update_query_raw(query, params, k, v) if "query" not in query: query["query"] = {"match_all": {}} elif request.method == "POST": try: query = json.loads(request.json or request.data or request.form.keys()[0]) except (ValueError, IndexError): raise ValueError params = request.args for o in (params, query): if "from" in o: o["from"] = max(0, atoi(o["from"])) if "size" in o: o["size"] = min(RESULTS_MAX_SIZE, max(0, atoi(o["size"]))) return query, params
def search_annotations(): params = dict(request.args.items()) kwargs = dict() # Take limit and offset out of the parameters if "offset" in params: kwargs["offset"] = atoi(params.pop("offset"), default=None) if "limit" in params: kwargs["limit"] = atoi(params.pop("limit"), default=None) if "sort" in params: kwargs["sort"] = params.pop("sort") if "order" in params: kwargs["order"] = params.pop("order") # All remaining parameters are considered searched fields. kwargs["query"] = params if current_app.config.get("AUTHZ_ON"): # Pass the current user to do permission filtering on results kwargs["user"] = g.user results = g.annotation_class.search(**kwargs) total = g.annotation_class.count(**kwargs) return jsonify({"total": total, "rows": results})
def search_annotations(): kwargs = dict(request.args.items()) if 'offset' in kwargs: kwargs['offset'] = atoi(kwargs['offset']) if 'limit' in kwargs: kwargs['limit'] = atoi(kwargs['limit'], 20) results = g.annotation_class.search(**kwargs) total = g.annotation_class.count(**kwargs) return jsonify({'total': total, 'rows': results})
def search_annotations(): kwargs = dict(request.args.items()) if "offset" in kwargs: kwargs["offset"] = atoi(kwargs["offset"]) if "limit" in kwargs: kwargs["limit"] = atoi(kwargs["limit"], 20) results = Annotation.search(**kwargs) total = Annotation.count(**kwargs) return jsonify({"total": total, "rows": results})