(posts, ix=None, overwrite=False, add_func=add_index)
Create or update a search index of posts.
Create or update a search index of posts.
Create or update a search index of posts .
def index_posts(posts, ix=None, overwrite=False, add_func=add_index):
    """
    Create or update a search index of posts.
    """

    ix = ix or init_index()
    # The writer is asynchronous by default
    writer = AsyncWriter(ix)

    elapsed, progress = timer_func()
    total = posts.count()
    stream = islice(zip(count(1), posts), None)

    # Loop through posts and add to index
    for step, post in stream:
        progress(step, total=total, msg="posts indexed")
        add_func(post=post, writer=writer)

    # Commit to index
    if overwrite:
        logger.info("Overwriting the old index")
        writer.commit(mergetype=writing.CLEAR)
    else:
        logger.debug("Committing to index")
        writer.commit()

    elapsed(f"Committed {total} posts to index.")
def index_posts ( posts , ix = None , overwrite = False , add_func = add_index ) : ix = ix or init_index ( ) # The writer is asynchronous by default writer = AsyncWriter ( ix ) elapsed , progress = timer_func ( ) total = posts . count ( ) stream = islice ( zip ( count ( 1 ) , posts ) , None ) # Loop through posts and add to index for step , post in stream : progress ( step , total = total , msg = "posts indexed" ) add_func ( post = post , writer = writer ) # Commit to index if overwrite : logger . info ( "Overwriting the old index" ) writer . commit ( mergetype = writing . CLEAR ) else : logger . debug ( "Committing to index" ) writer . commit ( ) elapsed ( f"Committed {total} posts to index." )