Skip to content

Commit

Permalink
use mongodb search
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyThink committed Dec 6, 2024
1 parent 2d5d55b commit 87ada12
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions yyetsweb/databases/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def get_resource_data(self, resource_id: int, username: str) -> dict:

def search_resource(self, keyword: str, search_type: "str") -> dict:
# search_type: default,subtitle,douban,comment
# TODO
if os.getenv("MEILISEARCH"):
return self.meili_search(keyword, search_type)
else:
Expand All @@ -63,7 +62,18 @@ def meili_search(self, keyword: "str", search_type: "str") -> dict:
comment_data = hide_phone(self.search_comment(keyword))

if search_type == "subtitle":
subtitle_data = self.search_subtitle(keyword)
# TODO: just get data from mongodb for now.
subtitle_data = list(
self.db["subtitle"].find(
{
"$or": [
{"cnname": {"$regex": f".*{keyword}.*", "$options": "i"}},
{"enname": {"$regex": f".*{keyword}.*", "$options": "i"}},
]
},
{"_id": False},
)
)

if search_type == "default":
resource_data = self.search_yyets(keyword)
Expand Down

0 comments on commit 87ada12

Please sign in to comment.