def add_documents(meilisearch_index: Index, documents: List[dict]):
    """
    Add documents to the MeiliSearch Index.

    Params:
        meilisearch_index: MeiliSearch's Index.
        documents: Documents to index to MeiliSearch.
    """
    try:
        meilisearch_index.add_documents(documents)
    except:
        sys.exit("\033[31mAn error occurs while indexing to MeiliSearch...")
Example #2
0
def index_videos(meilisearch_index: Index, videos: list[dict]):
    """
    Index videos to the given index.

    Params
    ------
    meilisearch_index: Index
        MeiliSearch Index instance.
    videos: list[dict]
        Videos list to index to MeiliSearch.
    """
    # Store the total of videos of the current index
    index_total_videos = len(videos)

    # Store the chunk number
    chunk_pieces_number = 100

    # Index all videos in MeiliSearch
    for index, videos in enumerate(chunks(videos, chunk_pieces_number)):
        # Print progression
        print("%d/%d indexed." % (min((index + 1) * chunk_pieces_number,
                                      index_total_videos), index_total_videos),
              end="\r")

        # Index videos
        response = meilisearch_index.add_documents(videos)

        # Wait until it has been indexed
        meilisearch_index.wait_for_pending_update(response["updateId"],
                                                  timeout_in_ms=20000,
                                                  interval_in_ms=200)

    if index_total_videos > 0:
        print()