def factquery(): if request.method == "POST": if request.json: qs = request.json else: qs = dict(request.form).keys()[-1] elif 'q' in request.values: qs = {'query': {'query_string': { 'query': request.values['q'] }}} elif 'source' in request.values: qs = json.loads(urllib2.unquote(request.values['source'])) else: qs = {'query': {'match_all': {}}} return query(path='Fact',qry=qs)
def factdaily(): # TODO: should this accept user-provided queries too? So people can search # on the daily list? If so, just check the incoming query and build one # with a MUST that includes the following date-based restriction. qry = { 'query': { 'query_string': { 'query': datetime.now().strftime("%Y-%m-%d"), 'default_field':'created_date' } }, 'sort': [{"created_date.exact":{"order":"desc"}}] } r = query(path='Fact',qry=qry,raw=True) # TODO: decide if any control keys should be removed before displaying facts res = [i['_source'] for i in r.get('hits',{}).get('hits',[])] resp = make_response( json.dumps(res) ) resp.mimetype = "application/json" return resp