• search auto complete


    #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,

  • 相关阅读:
    RedisTemplate的rightpushAll()时的坑
    Redis操作HyperLogLog
    Redis做消息队列使用
    UML
    设计模式概述
    HTTP/HTTPS/TCP/IP协议
    SpringBoot特点
    虚拟机+kafka基础配置
    Spring学习
    SpringBoot配置文件
  • 原文地址:https://www.cnblogs.com/lexus/p/2518575.html
Copyright © 2020-2023  润新知