Skip to content

Commit

Permalink
add doc string
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyThink committed Nov 18, 2023
1 parent a3458eb commit c1a24cc
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 7 deletions.
87 changes: 84 additions & 3 deletions searchgram/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def check_ignore(message):
return True

@staticmethod
def __clean_user(user: "str"):
def clean_user(user: "str"):
if user is None:
return None
with contextlib.suppress(Exception):
Expand All @@ -52,8 +52,89 @@ def __clean_user(user: "str"):
def upsert(self, message):
pass

def search(self, keyword, _type=None, user=None, page=1, mode=None):
pass
def search(self, keyword, _type=None, user=None, page=1, mode=None) -> dict:
"""
:param keyword:
:param _type: ChatType.["BOT", "CHANNEL", "GROUP", "PRIVATE", "SUPERGROUP"]
:param user: username or id
:param page:
:param mode: exact match
:return:
"""

return {
"hits": [
{
"ID": "123456-1114100",
"_": "Message",
"id": 1114100,
"from_user": {
"_": "User",
"id": 260260121,
"is_self": True,
"is_contact": False,
"is_mutual_contact": False,
"is_deleted": False,
"is_bot": False,
"is_verified": False,
"is_restricted": False,
"is_scam": False,
"is_fake": False,
"is_support": False,
"is_premium": True,
"first_name": "Benny小可爱",
"status": "UserStatus.ONLINE",
"next_offline_date": "2023-11-18 16:35:09",
"username": "BennyThink",
"emoji_status": {"_": "EmojiStatus", "custom_emoji_id": 5377556559356238807},
"dc_id": 5,
"phone_number": "*********",
"photo": {
"_": "ChatPhoto",
"small_file_id": "AQADBQADtacxGxlBgw8AEAIAAxlBgw8ABNG47cEZeO_bAAQeBA",
"small_photo_unique_id": "AgADtacxGxlBgw8",
"big_file_id": "AQADBQADtacxGxlBgw8AEAMAAxlBgw8ABNG47cEZeO_bAAQeBA",
"big_photo_unique_id": "AgADtacxGxlBgw8",
},
},
"date": "2023-11-18 16:30:21",
"chat": {
"_": "Chat",
"id": 123456,
"type": "ChatType.PRIVATE",
"is_verified": False,
"is_restricted": False,
"is_scam": False,
"is_fake": False,
"is_support": False,
"username": "name_unknow",
"first_name": "ok",
"photo": {
"_": "ChatPhoto",
"small_file_id": "edfgh567",
"small_photo_unique_id": "ghjgh",
"big_file_id": "AQAeBA",
"big_photo_unique_id": "AgyebeVQ",
},
"dc_id": 5,
},
"mentioned": False,
"scheduled": False,
"from_scheduled": False,
"has_protected_content": False,
"text": "测试仪你",
"outgoing": True,
"timestamp": 1700321421,
}
],
"query": "测试",
"processingTimeMs": 1,
"hitsPerPage": 10,
"page": 1,
"totalPages": 1,
"totalHits": 1,
}

def ping(self) -> str:
pass
Expand Down
4 changes: 2 additions & 2 deletions searchgram/meili.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def upsert(self, message):
data = self.set_uid(message)
self.client.index("telegram").add_documents([data], primary_key="ID")

def search(self, keyword, _type=None, user=None, page=1, mode=None):
def search(self, keyword, _type=None, user=None, page=1, mode=None) -> dict:
if mode:
keyword = f'"{keyword}"'
user = self.__clean_user(user)
user = self.clean_user(user)
params = {
"hitsPerPage": 10,
"page": page,
Expand Down
4 changes: 2 additions & 2 deletions searchgram/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def search2(self, keyword, _type=None, user=None, page=1, mode=None):
return results

def ping(self) -> str:
count = self.col.count_documents({})
count = self.chat.count_documents({})
size = self.db.command("dbstats")["storageSize"]
return f"{count} messages, {sizeof_fmt(size)}"

def clear_db(self):
pass
self.client.drop_database("telegram")


if __name__ == "__main__":
Expand Down

0 comments on commit c1a24cc

Please sign in to comment.