
utils.py
About this file
It handles the search utilities to:
Recreate elasticsearch indices and request docs,
Return whether the elasticsearch index exists or not,
Delete all elasticsearch indices, ignoring errors,
Delete all elasticsearch request docs,
Create elasticsearch index with mappings for request docs,
Create elasticsearch request docs for every request db record,
To search requests matching the request parameters of the '/search/requests'
endpoints,
To convert dates in a specified time format,
Remove highlights for private and non-requester fields.
Code Check Report
No problems to report
Documentation drawn from source code
recreate():
Recreate elasticsearch indices and request docs.
index_exists():
Return whether the elasticsearch index exists or not.
delete_index():
Delete all elasticsearch indices, ignoring errors.
delete_docs():
Delete all elasticsearch request docs.
create_index():
Create elasticsearch index with mappings for request docs.
create_docs():
Create elasticsearch request docs for every request db record.
search_requests(
The arguments of this function match the request parametersof the '/search/requests' endpoints.All date related params expect strings in the format "mm/dd/yyyyAll sort related params expect "desc" or "asc"; other strings ignored:param query: string to query for:param foil_id: search by request id?:param title: search by title?:param agency_request_summary: search by agency request summary?:param description: search by description?:param requester_name: search by requester name?:param date_rec_from: date created/submitted from:param date_rec_to: date created/submitted to:param date_due_from: date due from:param date_due_to: date due to:param date_closed_from: date closed from:param date_closed_to: date closed to:param agency_ein: agency ein to filter by:param agency_user_guid: user (agency) guid to filter by:param open_: filter by opened requests?:param closed: filter by closed requests?:param in_progress: filter by in-progress requests?:param due_soon: filter by due-soon requests?:param overdue: filter by overdue requests?:param size: number of requests per page:param start: starting index of request result set:param sort_date_received: date created/submitted sort direction:param sort_date_due: date due sort direction:param sort_title: title sort direction:param tz_name: timezone name (e.g. "America/New_York"):param by_phrase: use phrase matching instead of full-text?:param highlight: return highlights?if True, will come at a slight performance cost (in order torestrict highlights to public fields, iterating over elasticsearchquery results is required):param for_csv: search for a csv exportif True, will not check the maximum value of size against MAX_RESULT_SIZE:return: elasticsearch json response with result information
datestr_local_to_utc(datestr):
RequestsDSLGenerator(object):
Class for generating dicts representing query dsl bodies for searching request docs.
__init__(
foil_id(self):
agency_user(self):
anonymous_user(self):
public_user(self):
queryless(self):
__must_query(self):
__must(self):
__should(self):
__get_filters(self):
convert_dates(results, dt_format=None, tz_name=None):
Replace datetime values of requests search results with adatetime object or a datetime string in the specified format.Dates can also be offset according to the given time zone name.:results: elasticsearch json results:dt_format: datetime string format:tz_name: time zone name
_process_highlights(results, requester_id=None):
Remove highlights for private and non-requester fields.Used for non-agency users.Why this is necessary:https://github.com/elastic/elasticsearch/issues/6787:param results: elasticsearch json search results:param requester_id: id of requester as it is exists in results