发布时间:2022-08-09 文章分类:编程知识 投稿人:李佳 字号: 默认 | | 超大 打印

#coding:utf-8
import _env
from os.path import join
from tokyo.dystopia import JDB, JDBOREADER, JDBONOLCK
from config import SEARCH_DB_PATH
from mmseg.search import seg_txt2
from hashlib import md5

def query_key_md5(query):
query = query.strip().split()
query.sort()
key = ' '.join(query)
md5key = md5(key).hexdigest()
return key, md5key

class SearchDb(object):
def __init__(self, name):
PATH_DB = join(SEARCH_DB_PATH, name)

jdb = JDB()
jdb.open(PATH_DB, JDBOREADER|JDBONOLCK)
self._jdb = jdb

def search(self, txt):
word_set = set(seg_txt2(txt.lower()))
keyword = ' '.join(word_set)
return self._jdb.search(keyword)

if __name__ == '__main__':
search_db_zsite_user = SearchDb('ZsiteTag')
print search_db_zsite_user.search('愤怒')

#search_db_po_note = SearchDb('PoNote')
#from model.po import Po
#from time import time
#begin = time()
#id_list = search_db_po_note.search('三而竭')
#print time() - begin
#print len(id_list)
#for i in Po.mc_get_list(id_list):
# print i.name_

#for i in search_db_po_note._jdb:
# print i
# for j in search_db_po_note._jdb[i]:
# print j,