# 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/document.py
# class DynamicDocument(with_metaclass(DynamicDocumentMeta, Document)):
#     def _process_source_key_value(self, key, value):
#         key, value = (
#             super(DynamicDocument, self)._process_source_key_value(key, value)
#         )
#         if isinstance(value, dict):
#             return key, DynamicDocument(**value)
#         return key, value
# 
# Path: elasticmagic/document.py
# def get_doc_type_for_hit(hit):
#     fields = hit.get('fields', {})
#     custom_doc_type = fields.get(DOC_TYPE_NAME_FIELD)
#     if custom_doc_type:
#         return custom_doc_type[0]
#     return hit['_type']


from .compat import string_types
from .document import DynamicDocument
from .document import get_doc_type_for_hit
class CountResult(Result):
    def __init__(self, raw_result):
        super(CountResult, self).__init__(raw_result)
        self.count = raw_result['count']


class ExistsResult(Result):
    def __init__(self, raw_result):
        super(ExistsResult, self).__init__(raw_result)
        self.exists = raw_result['exists']


class ExplainResult(Result):
    def __init__(self, raw_result, doc_cls_map=None, _store_hit=False):
        super(ExplainResult, self).__init__(raw_result)

        doc_cls_map = doc_cls_map or {}

        self.matched = raw_result['matched']
        self.explanation = raw_result['explanation']

        raw_hit = raw_result.get('get', {}).copy()
        self._id = raw_result['_id']
        self._type = raw_result['_type']
        self._index = raw_result['_index']
        self.hit = None
        if raw_hit:
            raw_hit['_id'] = raw_result['_id']
            raw_hit['_type'] = raw_result['_type']
            raw_hit['_index'] = raw_result['_index']

# 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/document.py
# class DynamicDocument(with_metaclass(DynamicDocumentMeta, Document)):
#     def _process_source_key_value(self, key, value):
#         key, value = (
#             super(DynamicDocument, self)._process_source_key_value(key, value)
#         )
#         if isinstance(value, dict):
#             return key, DynamicDocument(**value)
#         return key, value
# 
# Path: elasticmagic/document.py
# def get_doc_type_for_hit(hit):
#     fields = hit.get('fields', {})
#     custom_doc_type = fields.get(DOC_TYPE_NAME_FIELD)
#     if custom_doc_type:
#         return custom_doc_type[0]
#     return hit['_type']


# Path: elasticmagic/result.py
from .compat import string_types
from .document import DynamicDocument
from .document import get_doc_type_for_hit

class CountResult(Result):
    def __init__(self, raw_result):
        super(CountResult, self).__init__(raw_result)
        self.count = raw_result['count']


class ExistsResult(Result):
    def __init__(self, raw_result):
        super(ExistsResult, self).__init__(raw_result)
        self.exists = raw_result['exists']


class ExplainResult(Result):
    def __init__(self, raw_result, doc_cls_map=None, _store_hit=False):
        super(ExplainResult, self).__init__(raw_result)

        doc_cls_map = doc_cls_map or {}

        self.matched = raw_result['matched']
        self.explanation = raw_result['explanation']

        raw_hit = raw_result.get('get', {}).copy()
        self._id = raw_result['_id']
        self._type = raw_result['_type']
        self._index = raw_result['_index']
        self.hit = None
        if raw_hit:
            raw_hit['_id'] = raw_result['_id']
            raw_hit['_type'] = raw_result['_type']
            raw_hit['_index'] = raw_result['_index']

            doc_type = get_doc_type_for_hit(raw_hit)