#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 md5def query_key_md5(query):
query = query.strip().split()
query.sort()
key = ' '.join(query)
md5key = md5(key).hexdigest()
return key, md5keyclass SearchDb(object):
def __init__(self, name):
PATH_DB = join(SEARCH_DB_PATH, name)jdb = JDB()
jdb.open(PATH_DB, JDBOREADER|JDBONOLCK)
self._jdb = jdbdef 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,
转载于:https://www.cnblogs.com/lexus/archive/2012/05/25/2518575.html