Skip to content

Commit

Permalink
Merge #183
Browse files Browse the repository at this point in the history
183: Update comments r=curquiza a=curquiza



Co-authored-by: Clementine Urquizar <clementine@meilisearch.com>
  • Loading branch information
bors[bot] and curquiza authored Dec 7, 2020
2 parents 264b7bd + 1e7fba8 commit 3cc7536
Show file tree
Hide file tree
Showing 25 changed files with 552 additions and 320 deletions.
111 changes: 73 additions & 38 deletions meilisearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,34 @@ def create_index(self, uid, options=None):
Parameters
----------
uid: str
UID of the index
options: dict, optional
Options passed during index creation (ex: primaryKey)
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
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
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)

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' }])
indexes: list
List of indexes in dictionary format. (e.g [{ 'uid': 'movies' 'primaryKey': 'objectID' }])
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 self.http.get(self.config.paths.index)

Expand All @@ -70,20 +72,21 @@ def get_index(self, uid):
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.
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 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.
"""Create a local reference to an index identified by UID, without doing an HTTP call.
Calling this method doesn't create an index in the MeiliSearch instance, but grants access to all the other methods in the Index class.
Parameters
----------
Expand All @@ -100,23 +103,24 @@ def index(self, uid):
raise Exception('The index UID should not be None')

def get_or_create_index(self, uid, options=None):
"""Retrieve an index in MeiliSearch, or create it if it doesn't exist yet.
"""Get an index, or create it if it doesn't exist.
Parameters
----------
uid: str
UID of the index
options: dict, optional
options (optional): dict
Options passed during index creation (ex: primaryKey)
Returns
-------
index : Index
An Index instance containing the information of the retrieved or newly created index.
An instance of Index containing the information of the retrieved or newly created index.
Raises
------
MeiliSearchApiError
In case of any other error found here https://docs.meilisearch.com/references/#errors-status-code
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
"""
try:
index_instance = self.get_index(uid)
Expand All @@ -131,82 +135,113 @@ def get_all_stats(self):
Get information about database size and all indexes
https://docs.meilisearch.com/references/stats.html
Returns
----------
-------
stats: `dict`
Dictionnary containing stats about your MeiliSearch instance
Dictionary containing stats about your MeiliSearch instance.
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 self.http.get(self.config.paths.stat)

def health(self):
"""Get health of MeiliSearch
"""Get health of the MeiliSearch server.
`204` HTTP status response when MeiliSearch is healthy.
Raises
----------
HTTPError
If MeiliSearch is not healthy
------
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 self.http.get(self.config.paths.health)

def get_keys(self):
"""Get all keys created
"""Get all keys.
Get list of all the keys that were created and all their related information.
Get list of all the keys.
Returns
----------
-------
keys: list
List of keys and their information.
https://docs.meilisearch.com/references/keys.html#get-keys
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 self.http.get(self.config.paths.keys)

def get_version(self):
"""Get version MeiliSearch
Returns
----------
-------
version: dict
Information about the version of MeiliSearch.
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 self.http.get(self.config.paths.version)

def version(self):
"""Alias for get_version
Returns
----------
-------
version: dict
Information about the version of MeiliSearch.
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 self.get_version()

def create_dump(self):
"""Triggers the creation of a MeiliSearch dump
"""Trigger the creation of a MeiliSearch dump.
Returns
----------
-------
Dump: dict
Information about the dump.
https://docs.meilisearch.com/references/dump.html#create-a-dump
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 self.http.post(self.config.paths.dumps)

def get_dump_status(self, uid):
"""Retrieves the status of a MeiliSearch dump creation
"""Retrieve the status of a MeiliSearch dump creation.
Parameters
----------
uid: str
UID of the dump
UID of the dump.
Returns
----------
-------
Dump status: dict
Information about the dump status.
https://docs.meilisearch.com/references/dump.html#get-dump-status
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 self.http.get(
self.config.paths.dumps + '/' + str(uid) + '/status'
Expand Down
6 changes: 3 additions & 3 deletions meilisearch/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Config:
"""
A client's credentials and configuration parameters
Client's credentials and configuration parameters
"""

class Paths():
Expand All @@ -27,9 +27,9 @@ def __init__(self, url, api_key=None):
"""
Parameters
----------
url : str
url: str
The url to the MeiliSearch API (ex: http://localhost:7700)
api_key : str
api_key (optional): str
The optional API key to access MeiliSearch
"""

Expand Down
2 changes: 1 addition & 1 deletion meilisearch/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __str__(self):
return f'MeiliSearchApiError. Error code: {self.error_code}. Error message: {self.message}. Error documentation: {self.error_link}'

class MeiliSearchCommunicationError(MeiliSearchError):
"""Error connecting to MeiliSearch"""
"""Error when connecting to MeiliSearch"""

def __str__(self):
return f'MeiliSearchCommunicationError, {self.message}'
Loading

0 comments on commit 3cc7536

Please sign in to comment.