diff --git a/app/search/utils.py b/app/search/utils.py index 3d6f771d9..de4b09fb9 100644 --- a/app/search/utils.py +++ b/app/search/utils.py @@ -223,7 +223,8 @@ def search_requests(query, sort_title, tz_name, by_phrase=False, - highlight=False): + highlight=False, + for_csv=False): """ The arguments of this function match the request parameters of the '/search/requests' endpoints. @@ -260,6 +261,8 @@ def search_requests(query, if True, will come at a slight performance cost (in order to restrict highlights to public fields, iterating over elasticsearch query results is required) + :param for_csv: search for a csv export + if True, will not check the maximum value of size against MAX_RESULT_SIZE :return: elasticsearch json response with result information """ @@ -382,6 +385,9 @@ def datestr_local_to_utc(datestr): } ) + # Calculate result set size + result_set_size = size if for_csv else min(size, MAX_RESULT_SIZE) + # search / run query results = es.search( index=current_app.config["ELASTICSEARCH_INDEX"], @@ -404,7 +410,7 @@ def datestr_local_to_utc(datestr): 'title', 'agency_request_summary', 'description'], - size=min(size, MAX_RESULT_SIZE), + size=result_set_size, from_=start, sort=sort, ) diff --git a/app/search/views.py b/app/search/views.py index e168aeff5..c74a5c6b0 100644 --- a/app/search/views.py +++ b/app/search/views.py @@ -191,7 +191,8 @@ def requests_doc(doc_type): request.args.get('sort_date_submitted'), request.args.get('sort_date_due'), request.args.get('sort_title'), - tz_name + tz_name, + for_csv=True ) total = results["hits"]["total"] if total != 0: @@ -201,6 +202,8 @@ def requests_doc(doc_type): mailing_address = (r.requester.mailing_address if r.requester.mailing_address is not None else {}) + date_closed = result['_source'].get('date_closed', '') + date_closed = date_closed if str(date_closed) != str(list()) else '' writer.writerow([ result["_id"], result["_source"]["agency_name"], @@ -211,7 +214,7 @@ def requests_doc(doc_type): result["_source"]["date_created"], result["_source"]["date_submitted"], result["_source"]["date_due"], - result["_source"].get('date_closed', ''), + date_closed, result["_source"]["requester_name"], r.requester.email, r.requester.title,