Skip to content

Commit 28a0927

Browse files
committed
Replace IndexStats with CamelBase class
1 parent cab011b commit 28a0927

File tree

4 files changed

+8
-51
lines changed

4 files changed

+8
-51
lines changed

meilisearch/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def get_stats(self) -> IndexStats:
269269
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
270270
"""
271271
stats = self.http.get(f"{self.config.paths.index}/{self.uid}/{self.config.paths.stat}")
272-
return IndexStats(stats)
272+
return IndexStats(**stats)
273273

274274
@version_error_hint_message
275275
def search(self, query: str, opt_params: Optional[Mapping[str, Any]] = None) -> Dict[str, Any]:

meilisearch/models/index.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
11
from __future__ import annotations
22

33
from enum import Enum
4-
from typing import Any, Dict, Iterator, List, Optional, Union
4+
from typing import Dict, List, Optional, Union
55

6-
from camel_converter import to_snake
76
from camel_converter.pydantic_base import CamelBase
87

98

10-
class IndexStats:
11-
__dict: Dict
12-
13-
def __init__(self, doc: Dict[str, Any]) -> None:
14-
self.__dict = doc
15-
for key, val in doc.items():
16-
key = to_snake(key)
17-
if isinstance(val, dict):
18-
setattr(self, key, IndexStats(val))
19-
else:
20-
setattr(self, key, val)
21-
22-
def __getattr__(self, attr: str) -> Any:
23-
if attr in self.__dict.keys():
24-
return attr
25-
raise AttributeError(f"{self.__class__.__name__} object has no attribute {attr}")
26-
27-
def __iter__(self) -> Iterator:
28-
return iter(self.__dict__.items())
9+
class IndexStats(CamelBase):
10+
number_of_documents: int
11+
is_indexing: bool
12+
field_distribution: Dict[str, int]
2913

3014

3115
class Faceting(CamelBase):

tests/index/test_index_stats_meilisearch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ def test_get_stats_default(index_with_documents):
1313
response = index_with_documents().get_stats()
1414
assert isinstance(response, IndexStats)
1515
assert response.number_of_documents == 31
16-
assert hasattr(response.field_distribution, "genre")
17-
assert response.field_distribution.genre == 11
16+
assert "genre" in response.field_distribution
17+
assert response.field_distribution["genre"] == 11

tests/models/test_index.py

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

0 commit comments

Comments
 (0)