def append_states_query_for_advanced_search(params: Dict[str, Any], query: elastic.ElasticQuery): if params.get('exclude_states'): return spike_state = params.get('spike_state') states = str_to_array(params.get('state')) if len(states): # If any states are selected, then filter for these ONLY query.must.append(elastic.terms(field='state', values=states)) else: # Otherwise include/exclude Spiked/Killed based on the params provided if spike_state == WORKFLOW_STATE.DRAFT: query.must_not.append( elastic.term(field='state', value=WORKFLOW_STATE.SPIKED)) if not strtobool(params.get('include_killed', False)): query.must_not.append( elastic.term(field='state', value=WORKFLOW_STATE.KILLED))
def search_calendars(params: Dict[str, Any], query: elastic.ElasticQuery): if strtobool(params.get('no_calendar_assigned', False)): # The `no_calendar_assigned` param should override the `calendars` param return calendars = str_to_array(params.get('calendars')) num_calendars = len(calendars) if num_calendars == 1: query.must.append( elastic.term(field='calendars.qcode', value=calendars[0])) elif num_calendars > 1: query.must.append( elastic.terms(field='calendars.qcode', values=calendars))
def search_recurrence_id(params: Dict[str, Any], query: elastic.ElasticQuery): if len(params.get('recurrence_id') or ''): query.must.append( elastic.term(field='recurrence_id', value=params['recurrence_id']))
def search_posted(params: Dict[str, Any], query: elastic.ElasticQuery): if strtobool(params.get('posted', False)): query.must.append( elastic.term(field='pubstatus', value=POST_STATE.USABLE))
def search_location(params: Dict[str, Any], query: elastic.ElasticQuery): if len(params.get('location') or ''): query.must.append( elastic.term(field='location.qcode', value=params['location']))
def search_events(_: Dict[str, Any], query: elastic.ElasticQuery): query.must.append(elastic.term(field='type', value='event'))