@@ -14,73 +14,78 @@ class Index():
14
14
15
15
config = None
16
16
http = None
17
- uid = ""
17
+ uid = None
18
+ primary_key = None
18
19
19
- def __init__ (self , config , uid ):
20
+ def __init__ (self , config , uid , primary_key = None ):
20
21
"""
21
22
Parameters
22
23
----------
23
24
config : Config
24
- Config object containing permission and location of meilisearch
25
+ Config object containing permission and location of MeiliSearch.
25
26
uid: str
26
27
Uid of the index on which to perform the index actions.
27
28
index_path: str
28
- Index url path
29
+ Index url path.
29
30
"""
30
31
self .config = config
31
- self .uid = uid
32
32
self .http = HttpRequests (config )
33
+ self .uid = uid
34
+ self .primary_key = primary_key
33
35
34
36
def delete (self ):
35
- """Delete an index from meilisearch
37
+ """Delete the index.
36
38
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
42
43
"""
43
44
return self .http .delete ('{}/{}' .format (self .config .paths .index , self .uid ))
44
45
45
46
def update (self , ** body ):
46
- """Update an index from meilisearch
47
+ """Update the index.
47
48
48
49
Parameters
49
50
----------
50
51
body: **kwargs
51
52
Accepts primaryKey as an updatable parameter.
52
53
53
54
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.
58
58
"""
59
59
payload = {}
60
60
primary_key = body .get ('primaryKey' , None )
61
61
if primary_key is not None :
62
62
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
64
66
65
- def info (self ):
66
- """Get info of index
67
+ def fetch_info (self ):
68
+ """Fetch the info of the index.
67
69
68
70
Returns
69
- ----------
71
+ -------
70
72
index: `dict`
71
- Dictionnary containing index information.
73
+ Dictionnary containing the index information.
72
74
"""
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
74
78
75
79
def get_primary_key (self ):
76
- """Get the primary key
80
+ """Get the primary key.
77
81
78
82
Returns
79
- ----------
83
+ -------
80
84
primary_key: str
81
85
String containing primary key.
82
86
"""
83
- return self .info ()['primaryKey' ]
87
+ self .primary_key = self .fetch_info ()['primaryKey' ]
88
+ return self .primary_key
84
89
85
90
@staticmethod
86
91
def create (config , uid , options = None ):
@@ -89,14 +94,14 @@ def create(config, uid, options=None):
89
94
Parameters
90
95
----------
91
96
uid: str
92
- UID of the index
97
+ UID of the index.
93
98
options: dict, optional
94
- Options passed during index creation (ex: primaryKey)
99
+ Options passed during index creation (ex: { ' primaryKey': 'name' }).
95
100
96
101
Returns
97
102
-------
98
103
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.
100
105
Raises
101
106
------
102
107
HTTPError
@@ -108,41 +113,22 @@ def create(config, uid, options=None):
108
113
return HttpRequests (config ).post (config .paths .index , payload )
109
114
110
115
@staticmethod
111
- def get_indexes (config ):
112
- """Get all indexes from meilisearch.
116
+ def list_all (config ):
117
+ """Get all indexes
113
118
114
119
Returns
115
120
-------
116
121
indexes : list
117
- List of indexes (dict)
122
+ List of indexes. Each index is a dictionnary.
118
123
Raises
119
124
------
120
125
HTTPError
121
126
In case of any error found here https://docs.meilisearch.com/references/#errors-status-code
122
127
"""
123
128
return HttpRequests (config ).get (config .paths .index )
124
129
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
-
144
130
def get_all_update_status (self ):
145
- """Get all update status from MeiliSearch
131
+ """Get all update status
146
132
147
133
Returns
148
134
----------
@@ -158,7 +144,7 @@ def get_all_update_status(self):
158
144
)
159
145
160
146
def get_update_status (self , update_id ):
161
- """Get one update from MeiliSearch
147
+ """Get one update status
162
148
163
149
Parameters
164
150
----------
@@ -224,7 +210,7 @@ def get_stats(self):
224
210
)
225
211
226
212
def search (self , query , opt_params = None ):
227
- """Search in meilisearch
213
+ """Search in the index
228
214
229
215
Parameters
230
216
----------
0 commit comments