@@ -205,22 +205,29 @@ def __get_share_page(self):
205
205
class YYeTsOffline (YYeTsBase ):
206
206
label = "yyets offline"
207
207
208
- def __init__ (self , db = "yyets " , col = "resource " ):
208
+ def __init__ (self , db = "zimuzu " , col = "yyets " ):
209
209
super ().__init__ ()
210
210
self .mongo = pymongo .MongoClient (host = MONGO )
211
211
self .collection = self .mongo [db ][col ]
212
212
213
213
def search_preview (self , search_text : str ) -> dict :
214
214
logging .info ("[%s] Loading offline data from MongoDB..." , self .label )
215
- regex = re .compile (search_text , re .IGNORECASE )
216
- condition = {"name" : {"$regex" : regex }}
217
- data = self .collection .find (condition )
218
215
216
+ projection = {'_id' : False , 'data.info' : True }
217
+ data = self .collection .find ({
218
+ "$or" : [
219
+ {"data.info.cnname" : {'$regex' : f'.*{ search_text } .*' }},
220
+ {"data.info.enname" : {'$regex' : f'.*{ search_text } .*' }},
221
+ {"data.info.aliasname" : {'$regex' : f'.*{ search_text } .*' }},
222
+ ]},
223
+ projection
224
+ )
219
225
results = {}
220
226
for item in data :
221
- fake_url = "http://www.rrys2020.com/resource/{}" .format (item ["id" ])
227
+ info = item ["data" ]["info" ]
228
+ fake_url = "http://www.rrys2020.com/resource/{}" .format (info ["id" ])
222
229
url_hash = hashlib .sha1 (fake_url .encode ('u8' )).hexdigest ()
223
- results [url_hash ] = item [ "name" ]. replace ( " \n " , " " )
230
+ results [url_hash ] = info [ "cnname" ] + info [ "enname" ] + info [ "aliasname" ]
224
231
self .redis .hset (url_hash , mapping = {"class" : self .__class__ .__name__ , "url" : fake_url })
225
232
226
233
logging .info ("[%s] Offline search complete" , self .label )
@@ -230,11 +237,10 @@ def search_preview(self, search_text: str) -> dict:
230
237
def search_result (self , resource_url ) -> dict :
231
238
# yyets offline
232
239
self .url = resource_url
233
-
234
- data : dict = self .collection .find_one ({"url" : self .url })
235
- rid = data ["id" ]
236
- name = data ["data" ]["data" ]["info" ]["cnname" ]
237
- data .pop ("_id" )
240
+ # http://www.rrys2020.com/resource/10017
241
+ rid = self .url .split ("/resource/" )[1 ]
242
+ data : dict = self .collection .find_one ({"data.info.id" : int (rid )}, {'_id' : False })
243
+ name = data ["data" ]["info" ]["cnname" ]
238
244
self .data = {"all" : data , "share" : WORKERS .format (id = rid ), "cnname" : name }
239
245
return self .data
240
246
@@ -349,3 +355,8 @@ def class_to_tg(sub_class: str):
349
355
m = getattr (this_module , sub_name )
350
356
logging .info ("Mapping %s to %s" , cmd_name , m )
351
357
vars ()[cmd_name ] = m
358
+
359
+ if __name__ == '__main__' :
360
+ a = YYeTsOffline ()
361
+ v = a .search_preview ("逃避" )
362
+ print (v )
0 commit comments