def create_index(self, uid, primary_key=None, name=None):
        """Create an index.

        If the argument `uid` isn't passed in, it will be generated
        by MeiliSearch.

        Parameters
        ----------
        uid: str
            UID of the index
        primary_key: str, optional
            Attribute used as unique document identifier
        name: str, optional
            Name of the index
        Returns
        -------
        index : Index
            an instance of Index containing the information of the newly created index
        Raises
        ------
        HTTPError
            In case of any other error found here https://docs.meilisearch.com/references/#errors-status-code
        """
        index = Index.create(self.config,
                             uid=uid,
                             primary_key=primary_key,
                             name=name)
        return Index(self.config, uid=index['uid'])
Beispiel #2
0
    def create_index(self, uid, options=None):
        """Create an index.

        If the argument `uid` isn't passed in, it will be generated
        by MeiliSearch.

        Parameters
        ----------
        uid: str
            UID of the index
        options: dict, optional
            Options passed during index creation (ex: primaryKey)

        Returns
        -------
        index : Index
            an instance of Index containing the information of the newly created index
        Raises
        ------
        HTTPError
            In case of any other error found here https://docs.meilisearch.com/references/#errors-status-code
        """
        index = Index(self.config, uid)
        index.create(self.config, uid, options)
        return index
Beispiel #3
0
    def create_index(self, name, uid=None, schema=None):
        """Create an index.

        If the argument `uid` isn't passed in, it will be generated
        by meilisearch.

        Parameters
        ----------
        name: str
            Name of the index
        uid: str, optional
            uid of the index
        schema: dict, optional
            dict containing the schema of the index.
            https://docs.meilisearch.com/main_concepts/indexes.html#schema-definition
        Returns
        -------
        index : Index
            an instance of Index containing the information of the newly created index
        Raises
        ------
        HTTPError
            In case of any other error found here https://docs.meilisearch.com/references/#errors-status-code
        """
        index = Index.create(self.config, name=name, uid=uid, schema=schema)
        return Index(self.config,
                     name=index["name"],
                     uid=index["uid"],
                     schema=schema)
Beispiel #4
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()
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...")
Beispiel #6
0
    def get_index(self, uid):
        """Get an index.

        Raises
        ------
        HTTPError
            In case of any error found here https://docs.meilisearch.com/references/#errors-status-code
        Returns
        -------
        index : Index
            an instance of Index containing the information of the index found
        """
        return Index.get_index(self.config, uid=uid)
Beispiel #7
0
    def get_indexes(self):
        """Get all indexes.

        Raises
        ------
        HTTPError
            In case of any error found here https://docs.meilisearch.com/references/#errors-status-code
        Returns
        -------
        list
            List of indexes in dictionnary format. (e.g [{ 'uid': 'movies' 'primaryKey': 'objectID' }])
        """
        return Index.get_indexes(self.config)
Beispiel #8
0
    def index(self, uid):
        """Create a local reference to an index identified by `uid`, without doing an HTTP call.
        Calling this method doesn't create an index by itself, but grants access to all the other methods in the Index class.

        Parameters
        ----------
        uid: str
            UID of the index.

        Returns
        -------
        index : Index
            An Index instance.
        """
        if uid is not None:
            return Index(self.config, uid=uid)
        raise Exception('The index UID should not be None')
Beispiel #9
0
    def get_index(self, uid):
        """Get the index.
        This index should already exist.

        Parameters
        ----------
        uid: str
            UID of the index.

        Raises
        ------
        HTTPError
            In case of any error found here https://docs.meilisearch.com/references/#errors-status-code
        Returns
        -------
        index : Index
            An Index instance containing the information of the fetched index.
        """
        return Index(self.config, uid).fetch_info()
    def get_index(self, uid):
        """Get the index.
        This index should already exist.

        Parameters
        ----------
        uid: str
            UID of the index.

        Returns
        -------
        index : Index
            An Index instance containing the information of the fetched index.

        Raises
        ------
        MeiliSearchApiError
            An error containing details about why MeiliSearch can't process your request. MeiliSearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
        """
        return Index(self.config, uid).fetch_info()
    def create_index(self, uid, options=None):
        """Create an index.

        Parameters
        ----------
        uid: str
            UID of the index.
        options (optional): dict
            Options passed during index creation (ex: primaryKey).

        Returns
        -------
        index : Index
            An instance of Index containing the information of the newly created index.

        Raises
        ------
        MeiliSearchApiError
            An error containing details about why MeiliSearch can't process your request. MeiliSearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
        """
        return Index.create(self.config, uid, options)