# Path: seeker/registry.py
# def register(doc_class, app_label=None):
# 
# Path: seeker/utils.py
# def delete(obj, index=None, using=None):
#     """
#     Shortcut to delete a Django object from the ES index based on it's model class.
#     """
#     from django.contrib.contenttypes.models import ContentType
#     model_class = ContentType.objects.get_for_model(obj).model_class()
#     for doc_class in model_documents.get(model_class, []):
#         doc_using = using or doc_class._doc_type.using or 'default'
#         doc_index = index or doc_class._doc_type.index or getattr(settings, 'SEEKER_INDEX', 'seeker')
#         es = connections.get_connection(doc_using)
#         try:
#             es.delete(
#                 index=doc_index,
#                 doc_type=doc_class._doc_type.name,
#                 id=doc_class.get_id(obj),
#                 refresh=True
#             )
#         except NotFoundError:
#             # If this object wasn't indexed for some reason (maybe not in the document's queryset), no big deal.
#             pass
# 
# def index(obj, index=None, using=None):
#     """
#     Shortcut to index a Django object based on it's model class.
#     """
#     from django.contrib.contenttypes.models import ContentType
#     model_class = ContentType.objects.get_for_model(obj).model_class()
#     for doc_class in model_documents.get(model_class, []):
#         if not doc_class.queryset().filter(pk=obj.pk).exists():
#             continue
#         doc_using = using or doc_class._doc_type.using or 'default'
#         doc_index = index or doc_class._doc_type.index or getattr(settings, 'SEEKER_INDEX', 'seeker')
#         es = connections.get_connection(doc_using)
#         body = doc_class.serialize(obj)
#         doc_id = body.pop('_id', None)
#         es.index(
#             index=doc_index,
#             doc_type=doc_class._doc_type.name,
#             body=body,
#             id=doc_id,
#             refresh=True
#         )


from django.db.models import signals
from .registry import model_documents
from .utils import delete, index
import logging


logger = logging.getLogger(__name__)

class ModelIndexer(object):
    """
    Class that automatically indexes any new or deleted mapped model objects.
    """

    def connect_signal_handlers(self):
        """
        Connects save and delete signal handler for mapped models. Also checks each ModelIndex for any additional signal handling that may be needed. 
        """

        for model_class, document_classes in model_documents.items():
            signals.post_save.connect(self.handle_save, sender=model_class, weak=False)
            signals.post_delete.connect(self.handle_delete, sender=model_class, weak=False)

            for document_class in document_classes:
                document_class.connect_additional_signal_handlers(self)

    def disconnect_signal_handlers(self):

# Path: seeker/registry.py
# def register(doc_class, app_label=None):
# 
# Path: seeker/utils.py
# def delete(obj, index=None, using=None):
#     """
#     Shortcut to delete a Django object from the ES index based on it's model class.
#     """
#     from django.contrib.contenttypes.models import ContentType
#     model_class = ContentType.objects.get_for_model(obj).model_class()
#     for doc_class in model_documents.get(model_class, []):
#         doc_using = using or doc_class._doc_type.using or 'default'
#         doc_index = index or doc_class._doc_type.index or getattr(settings, 'SEEKER_INDEX', 'seeker')
#         es = connections.get_connection(doc_using)
#         try:
#             es.delete(
#                 index=doc_index,
#                 doc_type=doc_class._doc_type.name,
#                 id=doc_class.get_id(obj),
#                 refresh=True
#             )
#         except NotFoundError:
#             # If this object wasn't indexed for some reason (maybe not in the document's queryset), no big deal.
#             pass
# 
# def index(obj, index=None, using=None):
#     """
#     Shortcut to index a Django object based on it's model class.
#     """
#     from django.contrib.contenttypes.models import ContentType
#     model_class = ContentType.objects.get_for_model(obj).model_class()
#     for doc_class in model_documents.get(model_class, []):
#         if not doc_class.queryset().filter(pk=obj.pk).exists():
#             continue
#         doc_using = using or doc_class._doc_type.using or 'default'
#         doc_index = index or doc_class._doc_type.index or getattr(settings, 'SEEKER_INDEX', 'seeker')
#         es = connections.get_connection(doc_using)
#         body = doc_class.serialize(obj)
#         doc_id = body.pop('_id', None)
#         es.index(
#             index=doc_index,
#             doc_type=doc_class._doc_type.name,
#             body=body,
#             id=doc_id,
#             refresh=True
#         )


# Path: seeker/indexer.py
from django.db.models import signals
from .registry import model_documents
from .utils import delete, index
import logging



logger = logging.getLogger(__name__)

class ModelIndexer(object):
    """
    Class that automatically indexes any new or deleted mapped model objects.
    """

    def connect_signal_handlers(self):
        """
        Connects save and delete signal handler for mapped models. Also checks each ModelIndex for any additional signal handling that may be needed. 
        """

        for model_class, document_classes in model_documents.items():
            signals.post_save.connect(self.handle_save, sender=model_class, weak=False)
            signals.post_delete.connect(self.handle_delete, sender=model_class, weak=False)

            for document_class in document_classes:
                document_class.connect_additional_signal_handlers(self)

    def disconnect_signal_handlers(self):

        for model_class, document_classes in model_documents.items():