def index_documents(docs):
    pipe = DB.pipeline(transaction=False)
    for doc in docs:
        if (not doc):
            continue
        if (doc.get('_action') in ['delete', 'update']):
            key = keys.document_key(doc['_id']).encode()
            known_doc = get_document(key)
            if known_doc:
                deindex_document(known_doc)
        if (doc.get('_action') in ['index', 'update', None]):
            index_document(pipe, doc)
        (yield doc)
    try:
        pipe.execute()
    except redis.RedisError as e:
        msg = 'Error while importing document:\n{}\n{}'.format(doc, str(e))
        raise ValueError(msg)
def index_documents(docs):
    pipe = DB.pipeline(transaction=False)
    for doc in docs:
        if (not doc):
            continue
        if (doc.get('_action') in ['delete', 'update']):
            key = keys.document_key(doc['_id']).encode()
            known_doc = get_document(key)
            if known_doc:
                deindex_document(known_doc)
        if (doc.get('_action') in ['index', 'update', None]):
            index_document(pipe, doc)
        (yield doc)
    try:
        pipe.execute()
    except redis.RedisError as e:
        msg = 'Error while importing document:\n{}\n{}'.format(doc, str(e))
        raise ValueError(msg)