Esempio n. 1
0
 def __init__(self, url, apiKey=None):
     """
     Parameters
     ----------
     url : str
         The url to the MeiliSearch API (ex: http://localhost:7700)
     apiKey : str
         The optional API key for MeiliSearch
     """
     self.config = Config(url, apiKey)
     self.http = HttpRequests(self.config)
Esempio n. 2
0
 def __init__(self, config, uid):
     """
     Parameters
     ----------
     config : Config
         Config object containing permission and location of meilisearch
     uid: str
         Uid of the index on which to perform the index actions.
     index_path: str
         Index url path
     """
     self.config = config
     self.uid = uid
     self.http = HttpRequests(config)
Esempio n. 3
0
 def __init__(self, config, uid, primary_key=None):
     """
     Parameters
     ----------
     config : dict
         Config object containing permission and location of MeiliSearch.
     uid: str
         UID of the index on which to perform the index actions.
     primary_key (optional): str
         Primary-key of the index.
     """
     self.config = config
     self.http = HttpRequests(config)
     self.uid = uid
     self.primary_key = primary_key
Esempio n. 4
0
 def __init__(self, config, uid, primary_key=None):
     """
     Parameters
     ----------
     config : dict
         Config object containing MeiliSearch configuration data, such as url and API Key.
     uid: str
         UID of the index in which further actions will be performed.
     primary_key: str, optional
         Primary-key of the index.
     """
     self.config = config
     self.http = HttpRequests(config)
     self.uid = uid
     self.primary_key = primary_key
Esempio n. 5
0
    def create(cls, config, uid, options=None):
        """Create the index.

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

        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
        """
        if options is None:
            options = {}
        payload = {**options, 'uid': uid}
        index_dict = HttpRequests(config).post(config.paths.index, payload)
        return cls(config, index_dict['uid'], index_dict['primaryKey'])
Esempio n. 6
0
    def create(config, **body):
        """Create an index.

        Parameters
        ----------
            body: **kwargs
            Accepts uid, name and primaryKey as parameter.

        Returns
        -------
        index : Index
            an instance of Index containing the information of the newly created index
        Raises
        ------
        HTTPError
            In case of any error found here https://docs.meilisearch.com/references/#errors-status-code
        """
        payload = {}
        uid = body.get('uid', None)
        if uid is not None:
            payload['uid'] = uid
        name = body.get('name', None)
        if name is not None:
            payload['name'] = name
        primary_key = body.get('primary_key', None)
        if primary_key is not None:
            payload['primaryKey'] = primary_key
        return HttpRequests.post(config, Index.index_path, payload)
Esempio n. 7
0
    def create(config, name, uid=None, schema=None):
        """Create an index.

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

        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 error found here https://docs.meilisearch.com/references/#errors-status-code
        """

        payload = {}
        if name is not None:
            payload["name"] = name
        if uid is not None:
            payload["uid"] = uid
        if schema is not None:
            payload["schema"] = schema
        response = HttpRequests.post(config, Index.index_path, payload)
        return response.json()
Esempio n. 8
0
    def create(cls, config, uid, options=None):
        """Create the index.

        Parameters
        ----------
        uid: str
            UID of the index.
        options: dict, optional
            Options passed during index creation.
            Ex: Index.create('indexUID', { 'primaryKey': 'name' })

        Returns
        -------
        index : Index
            An Index instance containing the information of the newly created index.
        Raises
        ------
        HTTPError
            In case of any error found here https://docs.meilisearch.com/references/#errors-status-code
        """
        if options is None:
            options = {}
        payload = {**options, 'uid': uid}
        index_dict = HttpRequests(config).post(config.paths.index, payload)
        return cls(config, index_dict['uid'], index_dict['primaryKey'])
Esempio n. 9
0
    def add_settings(self, body):
        """Add settings to the given Index

        Add settings to the given index.
        https://docs.meilisearch.com/references/settings.html#add-or-update-settings
        Parameters
        ----------
        body: `dict`
            Dictionnary containing the settings of the index
            More information :
            https://docs.meilisearch.com/references/settings.html#add-or-update-settings

        Returns
        ----------
        document: `dict`
            Dictionnary containing the settings of the index
        """

        return HttpRequests.post(self.config, '{}/{}/{}'.format(
            self.index_path,
            self.uid,
            self.setting_path
        ),
                                 body
                                 ).json()
Esempio n. 10
0
    def get_version(self):
        """Get version meilisearch

        Returns
        ----------
        version: dict
            Information about version of meilisearch.
        """
        return HttpRequests.get(self.config, self.version_path).json()
Esempio n. 11
0
    def info(self):
        """Get info of index

        Returns
        ----------
        index: `dict`
            Dictionnary containing index information.
        """
        return HttpRequests.get(self.config, '{}/{}'.format(self.index_path, self.uid))
Esempio n. 12
0
    def delete(self):
        """Delete an index from meilisearch

        Returns
        ----------
        update: `dict`
            Dictionnary containing an update id to track the action:
            https://docs.meilisearch.com/references/updates.html#get-an-update-status
        """
        return HttpRequests.delete(self.config, '{}/{}'.format(self.index_path, self.uid))
Esempio n. 13
0
    def get_all_update_status(self):
        """Get all update status from MeiliSearch

        Returns
        ----------
        update: `list`
            List of all enqueued and processed actions of the index.
        """
        return HttpRequests.get(
            self.config, '{}/{}/{}'.format(self.index_path, self.uid,
                                           self.update_path))
Esempio n. 14
0
    def get_synonyms(self):
        """
        Get synonyms of an index

        Returns
        ----------
        settings: `dict`
            Dictionnary containing the synonyms of the index
        """
        return HttpRequests.get(self.config,
                                self.__settings_url_for(self.synonyms_path))
Esempio n. 15
0
    def get_stop_words(self):
        """
        Get stop words of an index

        Returns
        ----------
        settings: `list`
            List containing the stop words of the index
        """
        return HttpRequests.get(self.config,
                                self.__settings_url_for(self.stop_words_path))
Esempio n. 16
0
    def health(self):
        """Get health of meilisearch

        `204` http status response when meilisearch is healthy.

        Raises
        ----------
        HTTPError
            If meilisearch is not healthy
        """
        return HttpRequests.get(self.config, self.health_path)
Esempio n. 17
0
    def get_ranking_rules(self):
        """
        Get ranking rules of an index

        Returns
        ----------
        settings: `list`
            List containing the ranking rules of the index
        """
        return HttpRequests.get(
            self.config, self.__settings_url_for(self.ranking_rules_path))
Esempio n. 18
0
    def get_distinct_attribute(self):
        """
        Get distinct attribute of an index

        Returns
        ----------
        settings: `str`
            String containing the distinct attribute of the index
        """
        return HttpRequests.get(
            self.config, self.__settings_url_for(self.distinct_attribute_path))
Esempio n. 19
0
    def get_accept_new_fields(self):
        """
        Get accept-new-fields value of an index

        Returns
        ----------
        settings: `bool`
            Boolean containing the accept-new-fields value of the index
        """
        return HttpRequests.get(
            self.config, self.__settings_url_for(self.accept_new_fields_path))
Esempio n. 20
0
    def get_sys_info(self):
        """Get system information of meilisearch

        Get information about memory usage and processor usage.

        Returns
        ----------
        sys_info: dict
            Information about memory and processor usage.
        """
        return HttpRequests.get(self.config, self.sys_info_path).json()
Esempio n. 21
0
    def get_all_stats(config):
        """Get all stats of MeiliSearch

        Get information about databasesize and all indexes
        https://docs.meilisearch.com/references/stats.html
        Returns
        ----------
        stats: `dict`
            Dictionnary containing stats about your MeiliSearch instance
        """
        return HttpRequests.get(config, Stat.stat_path)
Esempio n. 22
0
    def get_keys(self):
        """Get all keys created

        Get list of all the keys that were created and all their related information.

        Returns
        ----------
        keys: list
            List of keys and their information.
            https://docs.meilisearch.com/references/keys.html#get-keys
        """
        return HttpRequests.get(self.config, self.key_path)
Esempio n. 23
0
    def get_stats(self):
        """Get stats of an index

        Get information about number of documents, fieldsfrequencies, ...
        https://docs.meilisearch.com/references/stats.html
        Returns
        ----------
        stats: `dict`
            Dictionnary containing stats about the given index.

        """
        return HttpRequests.get(self.config, '{}/{}'.format(self.stat_path, self.uid)).json()
Esempio n. 24
0
    def update_health(self, health):
        """Update health of meilisearch

        Update health of meilisearch to true or false.

        Parameters
        ----------
        health: bool
            Boolean reprensenting the healthyness of meilisearch. True for healthy.

        """
        return HttpRequests.put(self.config, self.health_path, { 'health': health })
Esempio n. 25
0
    def get_searchable_attributes(self):
        """
        Get searchable attributes of an index

        Returns
        ----------
        settings: `list`
            List containing the searchable attributes of the index
        """
        return HttpRequests.get(
            self.config,
            self.__settings_url_for(self.searchable_attributes_path))
Esempio n. 26
0
    def get_displayed_attributes(self):
        """
        Get displayed attributes of an index

        Returns
        ----------
        settings: `list`
            List containing the displayed attributes of the index
        """
        return HttpRequests.get(
            self.config,
            self.__settings_url_for(self.displayed_attributes_path))
Esempio n. 27
0
    def get_schema(self):
        """Get schema of index

        Returns
        ----------
        update: `dict`
            Schema definition
        """

        return HttpRequests.get(
            self.config, '{}/{}/{}'.format(self.index_path, self.uid,
                                           self.schema_path)).json()
Esempio n. 28
0
    def get_indexes(config):
        """Get all indexes from meilisearch.

        Returns
        -------
        indexes : list
            List of indexes (dict)
        Raises
        ------
        HTTPError
            In case of any error found here https://docs.meilisearch.com/references/#errors-status-code
        """
        return HttpRequests(config).get(config.paths.index)
Esempio n. 29
0
    def reset_synonyms(self):
        """Reset synonyms of an index to default values

        Returns
        ----------
        update: `dict`
            Dictionnary containing an update id to track the action:
            https://docs.meilisearch.com/references/updates.html#get-an-update-status
        """
        return HttpRequests.delete(
            self.config,
            self.__settings_url_for(self.synonyms_path),
        )
Esempio n. 30
0
    def get_settings(self):
        """Get settings of an index

        https://docs.meilisearch.com/references/settings.html

        Returns
        ----------
        settings: `dict`
            Dictionnary containing the settings of the index
        """
        return HttpRequests.get(
            self.config, '{}/{}/{}'.format(self.index_path, self.uid,
                                           self.setting_path))