def index_add_instance(sender, instance, **kwargs):
    """
    Receiver that should be called by the post_save signal and the m2m_changed
    signal.

    If the instance has an method get_search_string, then it is written
    into the search index. The method has to return an dictonary that can be
    used as keyword arguments to writer.add_document.
    """
    # TODO: This method blocks the search index. So in a multi thread environment
    #       this method can raise whoosh.store.LockError. Therefore it has to
    #       be done in tornado to support the big mode.
    #       See: https://pythonhosted.org/Whoosh/indexing.html#indexing-documents
    try:
        get_search_index_string = instance.get_search_index_string
    except __HOLE__:
        # If the instance is not searchable, then exit this signal early.
        return

    created = kwargs.get('created', False)

    writer_kwargs = {
        'id_collection': combine_id_and_collection(instance),
        'id': str(instance.pk),
        'collection': instance.get_collection_string(),
        'content': get_search_index_string()}

    with index.get_or_create_index().writer() as writer:
        if created:
            writer.add_document(**writer_kwargs)
        else:
            writer.update_document(**writer_kwargs)
dataset/ETHPy150Open OpenSlides/OpenSlides/openslides/utils/search.py/index_add_instance