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)
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)
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
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
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'])
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)
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()
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'])
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()
def get_version(self): """Get version meilisearch Returns ---------- version: dict Information about version of meilisearch. """ return HttpRequests.get(self.config, self.version_path).json()
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))
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))
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))
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))
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))
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)
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))
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))
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))
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()
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)
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)
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()
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 })
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))
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))
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()
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)
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), )
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))