def bill_keywords(bill): """ Get the keyword set for all of a bill's titles. """ keywords = keywordize(bill['title']) for title in bill['alternate_titles']: keywords = keywords.union(keywordize(title)) return keywords
def read(self, request): bill_fields = {'title': 1, 'created_at': 1, 'updated_at': 1, 'bill_id': 1, 'type': 1, 'state': 1, 'session': 1, 'chamber': 1, 'subjects': 1, '_type': 1} # normal mongo search logic _filter = _build_mongo_filter(request, ('state', 'chamber', 'subjects')) # process full-text query query = request.GET.get('q') if query: keywords = list(keywordize(query)) _filter['_keywords'] = {'$all': keywords} # process search_window search_window = request.GET.get('search_window', '').lower() if search_window: if search_window == 'session': _filter['_current_session'] = True elif search_window == 'term': _filter['_current_term'] = True elif search_window.startswith('session:'): _filter['session'] = search_window.split('session:')[1] elif search_window.startswith('term:'): _filter['_term'] = search_window.split('term:')[1] elif search_window == 'all': pass else: resp = rc.BAD_REQUEST resp.write(": invalid search_window. Valid choices are " "'term', 'session' or 'all'") return resp # process updated_since since = request.GET.get('updated_since') if since: try: _filter['updated_at'] = {'$gte': datetime.datetime.strptime( since, "%Y-%m-%d %H:%M")} except ValueError: try: _filter['updated_at'] = {'$gte': datetime.datetime.strptime( since, "%Y-%m-%d")} except ValueError: resp = rc.BAD_REQUEST resp.write(": invalid updated_since parameter." " Please supply a date in YYYY-MM-DD format.") return resp # process sponsor_id sponsor_id = request.GET.get('sponsor_id') if sponsor_id: _filter['sponsors.leg_id'] = sponsor_id return list(db.bills.find(_filter, bill_fields))
def read(self, request): bill_fields = {'title': 1, 'created_at': 1, 'updated_at': 1, 'bill_id': 1, 'type': 1, 'state': 1, 'level': 1, 'country': 1, 'session': 1, 'chamber': 1, 'subjects': 1, '_type': 1} # replace with request's fields if they exist bill_fields = _build_field_list(request, bill_fields) # normal mongo search logic _filter = _build_mongo_filter(request, ('state', 'chamber', 'subjects', 'bill_id', 'bill_id__in')) # process full-text query query = request.GET.get('q') if query: keywords = list(keywordize(query)) _filter['_keywords'] = {'$all': keywords} # process search_window search_window = request.GET.get('search_window', '') if search_window: if search_window == 'session': _filter['_current_session'] = True elif search_window == 'term': _filter['_current_term'] = True elif search_window.startswith('session:'): _filter['session'] = search_window.split('session:')[1] elif search_window.startswith('term:'): _filter['_term'] = search_window.split('term:')[1] elif search_window == 'all': pass else: resp = rc.BAD_REQUEST resp.write(": invalid search_window. Valid choices are " "'term', 'session' or 'all'") return resp # process updated_since since = request.GET.get('updated_since') if since: try: _filter['updated_at'] = {'$gte': parse_param_dt(since)} except ValueError: resp = rc.BAD_REQUEST resp.write(": invalid updated_since parameter." " Please supply a date in YYYY-MM-DD format.") return resp # process sponsor_id sponsor_id = request.GET.get('sponsor_id') if sponsor_id: _filter['sponsors.leg_id'] = sponsor_id query = db.bills.find(_filter, bill_fields) # sorting sort = request.GET.get('sort') if sort == 'updated_at': query = query.sort([('updated_at', -1)]) return list(query)
def read(self, request): bill_fields = { 'title': 1, 'created_at': 1, 'updated_at': 1, 'bill_id': 1, 'type': 1, 'state': 1, 'level': 1, 'country': 1, 'session': 1, 'chamber': 1, 'subjects': 1, '_type': 1 } # replace with request's fields if they exist bill_fields = _build_field_list(request, bill_fields) # normal mongo search logic _filter = _build_mongo_filter( request, ('state', 'chamber', 'subjects', 'bill_id', 'bill_id__in')) # process full-text query query = request.GET.get('q') if query: keywords = list(keywordize(query)) _filter['_keywords'] = {'$all': keywords} # process search_window search_window = request.GET.get('search_window', '') if search_window: if search_window == 'session': _filter['_current_session'] = True elif search_window == 'term': _filter['_current_term'] = True elif search_window.startswith('session:'): _filter['session'] = search_window.split('session:')[1] elif search_window.startswith('term:'): _filter['_term'] = search_window.split('term:')[1] elif search_window == 'all': pass else: resp = rc.BAD_REQUEST resp.write(": invalid search_window. Valid choices are " "'term', 'session' or 'all'") return resp # process updated_since since = request.GET.get('updated_since') if since: try: _filter['updated_at'] = {'$gte': parse_param_dt(since)} except ValueError: resp = rc.BAD_REQUEST resp.write(": invalid updated_since parameter." " Please supply a date in YYYY-MM-DD format.") return resp # process sponsor_id sponsor_id = request.GET.get('sponsor_id') if sponsor_id: _filter['sponsors.leg_id'] = sponsor_id query = db.bills.find(_filter, bill_fields) # sorting sort = request.GET.get('sort') if sort == 'updated_at': query = query.sort([('updated_at', -1)]) return list(query)
def read(self, request): bill_fields = { "title": 1, "created_at": 1, "updated_at": 1, "bill_id": 1, "type": 1, "state": 1, "level": 1, "country": 1, "session": 1, "chamber": 1, "subjects": 1, "_type": 1, } # replace with request's fields if they exist bill_fields = _build_field_list(request, bill_fields) # normal mongo search logic _filter = _build_mongo_filter(request, ("state", "chamber", "subjects", "bill_id", "bill_id__in")) # process full-text query query = request.GET.get("q") if query: keywords = list(keywordize(query)) _filter["_keywords"] = {"$all": keywords} # process search_window search_window = request.GET.get("search_window", "") if search_window: if search_window == "session": _filter["_current_session"] = True elif search_window == "term": _filter["_current_term"] = True elif search_window.startswith("session:"): _filter["session"] = search_window.split("session:")[1] elif search_window.startswith("term:"): _filter["_term"] = search_window.split("term:")[1] elif search_window == "all": pass else: resp = rc.BAD_REQUEST resp.write(": invalid search_window. Valid choices are " "'term', 'session' or 'all'") return resp # process updated_since since = request.GET.get("updated_since") if since: try: _filter["updated_at"] = {"$gte": parse_param_dt(since)} except ValueError: resp = rc.BAD_REQUEST resp.write(": invalid updated_since parameter." " Please supply a date in YYYY-MM-DD format.") return resp # process sponsor_id sponsor_id = request.GET.get("sponsor_id") if sponsor_id: _filter["sponsors.leg_id"] = sponsor_id return list(db.bills.find(_filter, bill_fields))