# Path: elasticmagic/util.py
# def clean_params(params, **kwargs):
#     return {
#         p: v for p, v in chain(params.items(), kwargs.items())
#         if v is not None
#     }
# 
# 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/types.py
# def instantiate(typeobj, *args, **kwargs):
#     if inspect.isclass(typeobj):
#         return typeobj(*args, **kwargs)
#     return typeobj
# 
# class Type(object):
#     python_type = None
# 
#     def __init__(self):
#         self.sub_type = None
#         self.doc_cls = None
# 
#     def to_python(self, value):
#         if value is None:
#             return None
#         if self.python_type is not None:
#             return self.python_type(value)
#         return value
# 
#     def to_python_single(self, value):
#         return self.to_python(value)
# 
#     def from_python(self, value, compiler, validate=False):
#         return value
# 
# 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):


import inspect
import operator
from itertools import count
from .util import clean_params, collect_doc_classes
from .types import instantiate, Type
from .compat import string_types, Mapping
            pre_tags=pre_tags,
            post_tags=post_tags,
            fragment_size=fragment_size,
            number_of_fragments=number_of_fragments,
            order=order,
            encoder=encoder,
            require_field_match=require_field_match,
            boundary_max_scan=boundary_max_scan,
            highlight_query=highlight_query,
            matched_fields=matched_fields,
            fragment_offset=fragment_offset,
            no_match_size=no_match_size,
            phrase_limit=phrase_limit,
            **kwargs
        )


class Field(Expression, FieldOperators):
    __visit_name__ = 'field'

    _counter = count()

    def __init__(self, *args, **kwargs):
        self._name = None
        self._type = None
        if len(args) == 1:
            if isinstance(args[0], string_types):
                self._name = args[0]
            elif (
                    isinstance(args[0], Type) or (

# Path: elasticmagic/util.py
# def clean_params(params, **kwargs):
#     return {
#         p: v for p, v in chain(params.items(), kwargs.items())
#         if v is not None
#     }
# 
# 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/types.py
# def instantiate(typeobj, *args, **kwargs):
#     if inspect.isclass(typeobj):
#         return typeobj(*args, **kwargs)
#     return typeobj
# 
# class Type(object):
#     python_type = None
# 
#     def __init__(self):
#         self.sub_type = None
#         self.doc_cls = None
# 
#     def to_python(self, value):
#         if value is None:
#             return None
#         if self.python_type is not None:
#             return self.python_type(value)
#         return value
# 
#     def to_python_single(self, value):
#         return self.to_python(value)
# 
#     def from_python(self, value, compiler, validate=False):
#         return value
# 
# 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/expression.py
import inspect
import operator
from itertools import count
from .util import clean_params, collect_doc_classes
from .types import instantiate, Type
from .compat import string_types, Mapping

            pre_tags=pre_tags,
            post_tags=post_tags,
            fragment_size=fragment_size,
            number_of_fragments=number_of_fragments,
            order=order,
            encoder=encoder,
            require_field_match=require_field_match,
            boundary_max_scan=boundary_max_scan,
            highlight_query=highlight_query,
            matched_fields=matched_fields,
            fragment_offset=fragment_offset,
            no_match_size=no_match_size,
            phrase_limit=phrase_limit,
            **kwargs
        )


class Field(Expression, FieldOperators):
    __visit_name__ = 'field'

    _counter = count()

    def __init__(self, *args, **kwargs):
        self._name = None
        self._type = None
        if len(args) == 1:
            if isinstance(args[0], string_types):
                self._name = args[0]
            elif (
                    isinstance(args[0], Type) or (

                        inspect.isclass(args[0]) and issubclass(args[0], Type)