def search_date_today(params: Dict[str, Any], query: elastic.ElasticQuery): if params.get('date_filter') == elastic.DATE_RANGE.TODAY: time_zone = get_time_zone(params) query.filter.append( elastic.bool_or([ elastic.range_today( elastic.ElasticRangeParams(field='dates.start', time_zone=time_zone)), elastic.range_today( elastic.ElasticRangeParams(field='dates.end', time_zone=time_zone)), elastic.bool_and([ elastic.field_range( elastic.ElasticRangeParams( field='dates.start', lt='now/d', time_zone=time_zone, )), elastic.field_range( elastic.ElasticRangeParams(field='dates.end', gt='now+24h/d', time_zone=time_zone)) ]) ]))
def search_date_next_week(params: Dict[str, Any], query: elastic.ElasticQuery): if params.get('date_filter') == elastic.DATE_RANGE.NEXT_WEEK: time_zone = get_time_zone(params) start_of_week = int(params.get('start_of_week') or 0) query.filter.append( elastic.bool_or([ elastic.range_next_week( elastic.ElasticRangeParams(field='dates.start', time_zone=time_zone, start_of_week=start_of_week)), elastic.range_next_week( elastic.ElasticRangeParams(field='dates.end', time_zone=time_zone, start_of_week=start_of_week)), elastic.bool_and([ elastic.field_range( elastic.ElasticRangeParams( field='dates.start', lt=elastic.start_of_next_week(start_of_week), time_zone=time_zone)), elastic.field_range( elastic.ElasticRangeParams( field='dates.end', gte=elastic.end_of_next_week(start_of_week), time_zone=time_zone)) ]) ]))
def search_calendars_and_agendas(params: Dict[str, Any], query: elastic.ElasticQuery): or_query = elastic.ElasticQuery() events.search_calendars(params, or_query) planning.search_agendas(params, or_query) if len(or_query.must) == 1: query.must.append(or_query.must[0]) elif len(or_query.must) > 1: query.must.append( elastic.bool_or( or_query.must ) )
def search_date_range(params: Dict[str, Any], query: elastic.ElasticQuery): date_filter, start_date, end_date, tz_offset = get_date_params(params) if not date_filter and start_date and end_date: query.filter.append( elastic.bool_or([ elastic.bool_and([ elastic.date_range( elastic.ElasticRangeParams(field='dates.start', gte=start_date, time_zone=tz_offset)), elastic.date_range( elastic.ElasticRangeParams(field='dates.end', lte=end_date, time_zone=tz_offset)), ]), elastic.bool_and([ elastic.date_range( elastic.ElasticRangeParams(field='dates.start', lt=start_date, time_zone=tz_offset)), elastic.date_range( elastic.ElasticRangeParams(field='dates.end', gt=end_date, time_zone=tz_offset)) ]), elastic.bool_or([ elastic.date_range( elastic.ElasticRangeParams(field='dates.start', gte=start_date, lte=end_date, time_zone=tz_offset)), elastic.date_range( elastic.ElasticRangeParams(field='dates.end', gte=start_date, lte=end_date, time_zone=tz_offset)) ]) ]))
def search_dates(params: Dict[str, Any], query: elastic.ElasticQuery): if params.get('exclude_dates'): return event_query = elastic.ElasticQuery() events.search_events(params, event_query) events.search_dates(params, event_query) planning_query = elastic.ElasticQuery() planning.search_planning(params, planning_query) planning.search_dates(params, planning_query) query.sort = planning_query.sort planning_query.sort = [] query.must.append( elastic.bool_or([ event_query.build()['query'], planning_query.build()['query'] ]) )
def search_date_last_24_hours(params: Dict[str, Any], query: elastic.ElasticQuery): if params.get('date_filter') == elastic.DATE_RANGE.LAST_24: time_zone = get_time_zone(params) query.filter.append( elastic.bool_or([ elastic.range_last_24_hours( elastic.ElasticRangeParams(field='dates.start', time_zone=time_zone)), elastic.range_last_24_hours( elastic.ElasticRangeParams(field='dates.end', time_zone=time_zone)), elastic.bool_and([ elastic.field_range( elastic.ElasticRangeParams(field='dates.start', lt='now-24h', time_zone=time_zone)), elastic.field_range( elastic.ElasticRangeParams(field='dates.end', gt='now', time_zone=time_zone)) ]) ]))