Skip to content

Commit 158a5fd

Browse files
committed
Integrate Stat into Client and Index
1 parent 3ff44c7 commit 158a5fd

File tree

3 files changed

+64
-74
lines changed

3 files changed

+64
-74
lines changed

meilisearch/client.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from meilisearch.index import Index
22
from meilisearch.config import Config
3-
from meilisearch.stat import Stat
3+
# from meilisearch.stat import Stat
44
from meilisearch._httprequests import HttpRequests
55

66
class Client():
@@ -17,6 +17,7 @@ class Client():
1717
key_path = 'keys'
1818
sys_info_path = 'sys-info'
1919
version_path = 'version'
20+
stat_path = 'stats'
2021

2122
def __init__(self, url, apiKey=None):
2223
"""
@@ -86,14 +87,16 @@ def get_index(self, uid):
8687
return Index.get_index(self.config, uid=uid)
8788

8889
def get_all_stats(self):
89-
"""Get statistics about indexes, database size and update date.
90+
"""Get all stats of MeiliSearch
9091
92+
Get information about databasesize and all indexes
93+
https://docs.meilisearch.com/references/stats.html
9194
Returns
92-
-------
93-
stats : dict
94-
Dictionnary with information about indexes, database size and update date.
95+
----------
96+
stats: `dict`
97+
Dictionnary containing stats about your MeiliSearch instance
9598
"""
96-
return Stat.get_all_stats(self.config)
99+
return HttpRequests.get(self.config, self.stat_path)
97100

98101
def health(self):
99102
"""Get health of meilisearch

meilisearch/index.py

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from meilisearch._httprequests import HttpRequests
22
from meilisearch.document import Document
33
from meilisearch.search import Search
4-
from meilisearch.stat import Stat
4+
# from meilisearch.stat import Stat
55
from meilisearch.setting import Setting
66

77
# pylint: disable=too-many-ancestors
8-
class Index(Document, Search, Stat, Setting):
8+
class Index(Document, Search, Setting):
99
"""
1010
Indexes routes wrapper
1111
@@ -19,6 +19,7 @@ class Index(Document, Search, Stat, Setting):
1919
"""
2020
index_path = 'indexes'
2121
update_path = 'updates'
22+
stat_path = 'stats'
2223
uid = ""
2324

2425
class Update:
@@ -35,6 +36,38 @@ class Update:
3536
"""
3637

3738

39+
def __init__(self, parent_path, config, uid=None, name=None):
40+
"""
41+
Parameters
42+
----------
43+
config : Config
44+
Config object containing permission and location of MeiliSearch
45+
name: str
46+
Name of the index on which to perform the index actions.
47+
uid: str
48+
Uid of the index on which to perform the index actions.
49+
index_path: str
50+
Index url path
51+
"""
52+
self.config = config
53+
self.name = name
54+
self.uid = uid
55+
self.index_path = parent_path
56+
57+
class Stat:
58+
"""
59+
Stats routes wrapper
60+
61+
Index's parent that gives access to all the stats methods of MeiliSearch.
62+
https://docs.meilisearch.com/references/stats.html#get-stat-of-an-index
63+
64+
Attributes
65+
----------
66+
stat_path:
67+
Version url path
68+
"""
69+
70+
3871
def __init__(self, parent_path, config, uid=None, name=None):
3972
"""
4073
Parameters
@@ -66,7 +99,7 @@ def __init__(self, config, uid):
6699
"""
67100
Search.__init__(self, Index.index_path, config, uid)
68101
Document.__init__(self, Index.index_path, config, uid)
69-
Stat.__init__(self, Index.index_path, config, uid)
102+
# Stat.__init__(self, Index.index_path, config, uid)
70103
Setting.__init__(self, Index.index_path, config, uid)
71104
self.config = config
72105
self.uid = uid
@@ -224,3 +257,22 @@ def get_update_status(self, update_id):
224257
update_id
225258
)
226259
)
260+
261+
def get_stats(self):
262+
"""Get stats of an index
263+
264+
Get information about number of documents, fieldsfrequencies, ...
265+
https://docs.meilisearch.com/references/stats.html
266+
Returns
267+
----------
268+
stats: `dict`
269+
Dictionnary containing stats about the given index.
270+
"""
271+
return HttpRequests.get(
272+
self.config,
273+
'{}/{}/{}'.format(
274+
self.index_path,
275+
self.uid,
276+
self.stat_path,
277+
)
278+
)

meilisearch/stat.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)