# Path: api/theatrics/handlers/helpers.py
# @with_params(ListParams)
# async def get_list(request, query, type_=None, relations={},
#                    page=1, page_size=20, fields=(), expand=()):
#     items, count, took = await search(query, type_, page, page_size, fields)
# 
#     expanding_relations = project(relations, expand)
#     items = await expand_multiple_items(items, expanding_relations)
# 
#     previous = get_previous_page_uri(request, page, page_size)
#     next_ = get_next_page_uri(request, page, page_size, count)
# 
#     return {
#         'count': count,
#         'items': items,
#         'took': took,
#         'previous': previous,
#         'next': next_,
#     }
# 
# Path: api/theatrics/handlers/v1/events.py
# EXPANDABLE_RELATIONS = {
#     'place': ('place', (
#         'location', 'name', 'full_name', 'tagline', 'kind', 'is_for_kids',
#         'is_stub', 'url', 'address', 'subway', 'coords', 'working_hours',
#         'phone_numbers', 'age_restriction',
#     )),
#     'parent': ('event', (
#         'location', 'name', 'full_name', 'tagline', 'kind', 'is_for_kids',
#         'is_premiere', 'tagline', 'age_restriction',
#     )),
#     'participants.agent': ('agent', (
#         'name', 'kind', 'is_stub',
#     ))
# }


import re
from datetime import datetime
from marshmallow import Schema, fields
from theatrics.scoring import get_default_score_functions
from theatrics.utils.handlers import with_params, json_response
from theatrics.utils.collections import get_all
from ..helpers import get_list
from .events import EXPANDABLE_RELATIONS






__all__ = ['search']


BROKEN_UP_EM_REGEX = re.compile(r'<\/em>([ \-"“”«»\.,;:–—]*)<em>')
EM_CONTENT_REGEX = re.compile(r'<em>(.*?)<\/em>')


class SearchParams(Schema):
    q = fields.String(required=True)
    location = fields.String()
    include_past = fields.Boolean()


@json_response
async def search(request):

# Path: api/theatrics/handlers/helpers.py
# @with_params(ListParams)
# async def get_list(request, query, type_=None, relations={},
#                    page=1, page_size=20, fields=(), expand=()):
#     items, count, took = await search(query, type_, page, page_size, fields)
# 
#     expanding_relations = project(relations, expand)
#     items = await expand_multiple_items(items, expanding_relations)
# 
#     previous = get_previous_page_uri(request, page, page_size)
#     next_ = get_next_page_uri(request, page, page_size, count)
# 
#     return {
#         'count': count,
#         'items': items,
#         'took': took,
#         'previous': previous,
#         'next': next_,
#     }
# 
# Path: api/theatrics/handlers/v1/events.py
# EXPANDABLE_RELATIONS = {
#     'place': ('place', (
#         'location', 'name', 'full_name', 'tagline', 'kind', 'is_for_kids',
#         'is_stub', 'url', 'address', 'subway', 'coords', 'working_hours',
#         'phone_numbers', 'age_restriction',
#     )),
#     'parent': ('event', (
#         'location', 'name', 'full_name', 'tagline', 'kind', 'is_for_kids',
#         'is_premiere', 'tagline', 'age_restriction',
#     )),
#     'participants.agent': ('agent', (
#         'name', 'kind', 'is_stub',
#     ))
# }


# Path: api/theatrics/handlers/v1/search.py
import re
from datetime import datetime
from marshmallow import Schema, fields
from theatrics.scoring import get_default_score_functions
from theatrics.utils.handlers import with_params, json_response
from theatrics.utils.collections import get_all
from ..helpers import get_list
from .events import EXPANDABLE_RELATIONS







__all__ = ['search']


BROKEN_UP_EM_REGEX = re.compile(r'<\/em>([ \-"“”«»\.,;:–—]*)<em>')
EM_CONTENT_REGEX = re.compile(r'<em>(.*?)<\/em>')


class SearchParams(Schema):
    q = fields.String(required=True)
    location = fields.String()
    include_past = fields.Boolean()


@json_response
async def search(request):

    results = await get_list(