@@ -14,73 +14,78 @@ class Index():
1414
1515 config = None
1616 http = None
17- uid = ""
17+ uid = None
18+ primary_key = None
1819
19- def __init__ (self , config , uid ):
20+ def __init__ (self , config , uid , primary_key = None ):
2021 """
2122 Parameters
2223 ----------
2324 config : Config
24- Config object containing permission and location of meilisearch
25+ Config object containing permission and location of MeiliSearch.
2526 uid: str
2627 Uid of the index on which to perform the index actions.
2728 index_path: str
28- Index url path
29+ Index url path.
2930 """
3031 self .config = config
31- self .uid = uid
3232 self .http = HttpRequests (config )
33+ self .uid = uid
34+ self .primary_key = primary_key
3335
3436 def delete (self ):
35- """Delete an index from meilisearch
37+ """Delete the index.
3638
37- Returns
38- ----------
39- update: `dict`
40- Dictionnary containing an update id to track the action:
41- https://docs.meilisearch.com/references/updates.html#get-an-update-status
39+ Raises
40+ ------
41+ HTTPError
42+ In case of any error found here https://docs.meilisearch.com/references/#errors-status-code
4243 """
4344 return self .http .delete ('{}/{}' .format (self .config .paths .index , self .uid ))
4445
4546 def update (self , ** body ):
46- """Update an index from meilisearch
47+ """Update the index.
4748
4849 Parameters
4950 ----------
5051 body: **kwargs
5152 Accepts primaryKey as an updatable parameter.
5253
5354 Returns
54- ----------
55- update: `dict`
56- Dictionnary containing an update id to track the action:
57- https://docs.meilisearch.com/references/updates.html#get-an-update-status
55+ -------
56+ index: `dict`
57+ Dictionnary containing index information.
5858 """
5959 payload = {}
6060 primary_key = body .get ('primaryKey' , None )
6161 if primary_key is not None :
6262 payload ['primaryKey' ] = primary_key
63- return self .http .put ('{}/{}' .format (self .config .paths .index , self .uid ), payload )
63+ response = self .http .put ('{}/{}' .format (self .config .paths .index , self .uid ), payload )
64+ self .primary_key = response ['primaryKey' ]
65+ return response
6466
65- def info (self ):
66- """Get info of index
67+ def fetch_info (self ):
68+ """Fetch the info of the index.
6769
6870 Returns
69- ----------
71+ -------
7072 index: `dict`
71- Dictionnary containing index information.
73+ Dictionnary containing the index information.
7274 """
73- return self .http .get ('{}/{}' .format (self .config .paths .index , self .uid ))
75+ index_dict = self .http .get ('{}/{}' .format (self .config .paths .index , self .uid ))
76+ self .primary_key = index_dict ['primaryKey' ]
77+ return index_dict
7478
7579 def get_primary_key (self ):
76- """Get the primary key
80+ """Get the primary key.
7781
7882 Returns
79- ----------
83+ -------
8084 primary_key: str
8185 String containing primary key.
8286 """
83- return self .info ()['primaryKey' ]
87+ self .primary_key = self .fetch_info ()['primaryKey' ]
88+ return self .primary_key
8489
8590 @staticmethod
8691 def create (config , uid , options = None ):
@@ -89,14 +94,14 @@ def create(config, uid, options=None):
8994 Parameters
9095 ----------
9196 uid: str
92- UID of the index
97+ UID of the index.
9398 options: dict, optional
94- Options passed during index creation (ex: primaryKey)
99+ Options passed during index creation (ex: { ' primaryKey': 'name' }).
95100
96101 Returns
97102 -------
98103 index : Index
99- an instance of Index containing the information of the newly created index
104+ An instance of Index containing the information of the newly created index.
100105 Raises
101106 ------
102107 HTTPError
@@ -108,41 +113,22 @@ def create(config, uid, options=None):
108113 return HttpRequests (config ).post (config .paths .index , payload )
109114
110115 @staticmethod
111- def get_indexes (config ):
112- """Get all indexes from meilisearch.
116+ def list_all (config ):
117+ """Get all indexes
113118
114119 Returns
115120 -------
116121 indexes : list
117- List of indexes (dict)
122+ List of indexes. Each index is a dictionnary.
118123 Raises
119124 ------
120125 HTTPError
121126 In case of any error found here https://docs.meilisearch.com/references/#errors-status-code
122127 """
123128 return HttpRequests (config ).get (config .paths .index )
124129
125- @staticmethod
126- def get_index (config , uid ):
127- """Get Index instance from given index
128-
129- If the argument `uid` aren't passed in, it will raise an exception.
130-
131- Returns
132- -------
133- index : Index
134- Instance of Index with the given index.
135- Raises
136- ------
137- Exception
138- If index UID is missing.
139- """
140- if uid is not None :
141- return Index (config , uid = uid )
142- raise Exception ('Uid is needed to find index' )
143-
144130 def get_all_update_status (self ):
145- """Get all update status from MeiliSearch
131+ """Get all update status
146132
147133 Returns
148134 ----------
@@ -158,7 +144,7 @@ def get_all_update_status(self):
158144 )
159145
160146 def get_update_status (self , update_id ):
161- """Get one update from MeiliSearch
147+ """Get one update status
162148
163149 Parameters
164150 ----------
@@ -224,7 +210,7 @@ def get_stats(self):
224210 )
225211
226212 def search (self , query , opt_params = None ):
227- """Search in meilisearch
213+ """Search in the index
228214
229215 Parameters
230216 ----------
0 commit comments