# Path: elasticmagic/compat.py
# PY2 = sys.version_info[0] == 2
# def force_unicode(value):
# def with_metaclass(meta, *bases):
#         def __new__(cls, name, this_bases, d):
#     class metaclass(meta):
# 
# Path: elasticmagic/compat.py
# PY2 = sys.version_info[0] == 2
# def force_unicode(value):
# def with_metaclass(meta, *bases):
#         def __new__(cls, name, this_bases, d):
#     class metaclass(meta):
# 
# Path: elasticmagic/util.py
# def _with_clone(fn):
#     @wraps(fn)
#     def wrapper(self, *args, **kwargs):
#         clone = self.clone()
#         res = fn(clone, *args, **kwargs)
#         if res is not None:
#             return res
#         return clone
#     return wrapper
# 
# Path: elasticmagic/util.py
# def merge_params(params, args, kwargs):
#     assert isinstance(args, Iterable), args
#     assert isinstance(kwargs, Mapping), kwargs
#     new = dict()
#     for a in args:
#         new.update(a)
#     new.update(kwargs)
#     return type(params)(params, **new)
# 
# def collect_doc_classes(expr):
#     if hasattr(expr, '_collect_doc_classes'):
#         return expr._collect_doc_classes()
# 
#     if isinstance(expr, dict):
#         return set().union(
#             *[collect_doc_classes(e)
#               for e in chain(expr.keys(), expr.values())]
#         )
# 
#     if isinstance(expr, (list, tuple)):
#         return set().union(*[collect_doc_classes(e) for e in expr])
# 
#     return set()
# 
# Path: elasticmagic/expression.py
# class Params(Expression, Mapping):
#     __visit_name__ = 'params'
# 
#     def __init__(self, *args, **kwargs):
#         params = {}
#         for d in args:
#             params.update(d)
#         params.update(kwargs)
#         self._params = {}
#         for k, v in clean_params(params).items():
#             if k.endswith('_') and not k.startswith('_'):
#                 k = k.rstrip('_')
#             self._params[k] = v
# 
#     def _collect_doc_classes(self):
#         return collect_doc_classes(self._params)
# 
#     def __len__(self):
#         return len(self._params)
# 
#     def __iter__(self):
#         return iter(self._params)
# 
#     def __getitem__(self, key):
#         return self._params[key]
# 
#     def __contains__(self, key):
#         return key in self._params
# 
# class Source(Expression):
#     __visit_name__ = 'source'
# 
#     def __init__(self, fields, include=None, exclude=None):
#         self.fields = fields
#         self.include = include
#         self.exclude = exclude
# 
#     def _collect_doc_classes(self):
#         return set().union(
#             collect_doc_classes(self.fields),
#             collect_doc_classes(self.include),
#             collect_doc_classes(self.exclude),
#         )
# 
# class Highlight(Expression):
#     __visit_name__ = 'highlight'
# 
#     def __init__(self, fields=None, **kwargs):
#         self.fields = fields
#         self.params = Params(kwargs)
# 
#     def _collect_doc_classes(self):
#         return set().union(
#             collect_doc_classes(self.fields),
#             collect_doc_classes(self.params),
#         )
# 
# class Rescore(Expression):
#     __visit_name__ = 'rescore'
# 
#     def __init__(self, rescorer, window_size=None,
#                  ):
#         self.rescorer = rescorer
#         self.window_size = window_size
# 
#     def _collect_doc_classes(self):
#         return collect_doc_classes(self.rescorer)
# 
# class Script(Expression):
#     __visit_name__ = 'script'
# 
#     def __init__(self, inline=None, lang=None,
#                  params=None, id=None, file=None):
#         self.inline = inline
#         self.id = id
#         self.lang = lang
#         self.file = file
#         self.script_params = params


import warnings
from abc import ABCMeta
from collections import namedtuple, OrderedDict
from .compat import zip, with_metaclass, string_types
from .compat import Iterable
from .util import _with_clone
from .util import merge_params, collect_doc_classes
from .expression import Params, Source, Highlight, Rescore, Script
    'BOOST', score_mode='sum', boost_mode='sum'
)


class BaseSearchQuery(with_metaclass(ABCMeta)):
    _q = None
    _source = None
    _fields = None
    _filters = ()
    _filters_meta = ()
    _post_filters = ()
    _post_filters_meta = ()
    _order_by = ()
    _aggregations = Params()
    _ext = Params()
    _function_scores = OrderedDict([
        (
            BOOST_FUNCTION_SCORE.name,
            _FunctionScore((), BOOST_FUNCTION_SCORE.settings)
        ),
        (
            GENERAL_FUNCTION_SCORE.name,
            _FunctionScore((), GENERAL_FUNCTION_SCORE.settings)
        ),
    ])
    _limit = None
    _offset = None
    _min_score = None
    _rescores = ()
    _suggest = Params()

# Path: elasticmagic/compat.py
# PY2 = sys.version_info[0] == 2
# def force_unicode(value):
# def with_metaclass(meta, *bases):
#         def __new__(cls, name, this_bases, d):
#     class metaclass(meta):
# 
# Path: elasticmagic/compat.py
# PY2 = sys.version_info[0] == 2
# def force_unicode(value):
# def with_metaclass(meta, *bases):
#         def __new__(cls, name, this_bases, d):
#     class metaclass(meta):
# 
# Path: elasticmagic/util.py
# def _with_clone(fn):
#     @wraps(fn)
#     def wrapper(self, *args, **kwargs):
#         clone = self.clone()
#         res = fn(clone, *args, **kwargs)
#         if res is not None:
#             return res
#         return clone
#     return wrapper
# 
# Path: elasticmagic/util.py
# def merge_params(params, args, kwargs):
#     assert isinstance(args, Iterable), args
#     assert isinstance(kwargs, Mapping), kwargs
#     new = dict()
#     for a in args:
#         new.update(a)
#     new.update(kwargs)
#     return type(params)(params, **new)
# 
# def collect_doc_classes(expr):
#     if hasattr(expr, '_collect_doc_classes'):
#         return expr._collect_doc_classes()
# 
#     if isinstance(expr, dict):
#         return set().union(
#             *[collect_doc_classes(e)
#               for e in chain(expr.keys(), expr.values())]
#         )
# 
#     if isinstance(expr, (list, tuple)):
#         return set().union(*[collect_doc_classes(e) for e in expr])
# 
#     return set()
# 
# Path: elasticmagic/expression.py
# class Params(Expression, Mapping):
#     __visit_name__ = 'params'
# 
#     def __init__(self, *args, **kwargs):
#         params = {}
#         for d in args:
#             params.update(d)
#         params.update(kwargs)
#         self._params = {}
#         for k, v in clean_params(params).items():
#             if k.endswith('_') and not k.startswith('_'):
#                 k = k.rstrip('_')
#             self._params[k] = v
# 
#     def _collect_doc_classes(self):
#         return collect_doc_classes(self._params)
# 
#     def __len__(self):
#         return len(self._params)
# 
#     def __iter__(self):
#         return iter(self._params)
# 
#     def __getitem__(self, key):
#         return self._params[key]
# 
#     def __contains__(self, key):
#         return key in self._params
# 
# class Source(Expression):
#     __visit_name__ = 'source'
# 
#     def __init__(self, fields, include=None, exclude=None):
#         self.fields = fields
#         self.include = include
#         self.exclude = exclude
# 
#     def _collect_doc_classes(self):
#         return set().union(
#             collect_doc_classes(self.fields),
#             collect_doc_classes(self.include),
#             collect_doc_classes(self.exclude),
#         )
# 
# class Highlight(Expression):
#     __visit_name__ = 'highlight'
# 
#     def __init__(self, fields=None, **kwargs):
#         self.fields = fields
#         self.params = Params(kwargs)
# 
#     def _collect_doc_classes(self):
#         return set().union(
#             collect_doc_classes(self.fields),
#             collect_doc_classes(self.params),
#         )
# 
# class Rescore(Expression):
#     __visit_name__ = 'rescore'
# 
#     def __init__(self, rescorer, window_size=None,
#                  ):
#         self.rescorer = rescorer
#         self.window_size = window_size
# 
#     def _collect_doc_classes(self):
#         return collect_doc_classes(self.rescorer)
# 
# class Script(Expression):
#     __visit_name__ = 'script'
# 
#     def __init__(self, inline=None, lang=None,
#                  params=None, id=None, file=None):
#         self.inline = inline
#         self.id = id
#         self.lang = lang
#         self.file = file
#         self.script_params = params


# Path: elasticmagic/search.py
import warnings
from abc import ABCMeta
from collections import namedtuple, OrderedDict
from .compat import zip, with_metaclass, string_types
from .compat import Iterable
from .util import _with_clone
from .util import merge_params, collect_doc_classes
from .expression import Params, Source, Highlight, Rescore, Script

    'BOOST', score_mode='sum', boost_mode='sum'
)


class BaseSearchQuery(with_metaclass(ABCMeta)):
    _q = None
    _source = None
    _fields = None
    _filters = ()
    _filters_meta = ()
    _post_filters = ()
    _post_filters_meta = ()
    _order_by = ()
    _aggregations = Params()
    _ext = Params()
    _function_scores = OrderedDict([
        (
            BOOST_FUNCTION_SCORE.name,
            _FunctionScore((), BOOST_FUNCTION_SCORE.settings)
        ),
        (
            GENERAL_FUNCTION_SCORE.name,
            _FunctionScore((), GENERAL_FUNCTION_SCORE.settings)
        ),
    ])
    _limit = None
    _offset = None
    _min_score = None
    _rescores = ()
    _suggest = Params()

    _highlight = Params()