def searchmulu(): '''搜索标题, GET方法为目录部典籍查找所用''' if request.method == "GET": title = request.GET.title # 去除HTML标签、注释、卷数, 留下标题 title = re.sub( r'<.*?>', '', title) # title=[34]<span style="color:red">阿</span>差末菩薩經 title = re.sub(r'\(.*?\)', '', title) title = re.sub(r'\[\w*?\]', '', title) title = re.sub(r'[一二三四五六七八九十百]+卷', '', title) else: title = request.forms.content if ts.detect(title)['confidence'] == 's': # title = opencc.convert(title, config='s2t.json') title = convert2t(title) results = [] if not title: return {'results': results} for idx in ss.search(title): title0 = idx hl = ss.titles[idx] zang = idx.split('n')[0] # T01 juan = get_all_juan(idx)[0] # 001 an = f"/xml/{zang}/{idx}_{juan}.xml" # T01n0002_001.xml results.append({'hl': hl, 'an': an, 'title': title0, 'author': ''}) if request.method == "GET": # 0个结果页面不动, 多个结果自己选择 if len(results) == 0: abort(304) if len(results) == 1: redirect(an) if len(results) > 1: pass return {'results': results}
def search_post(): # global qp # print(request.POST) content = request.GET.content if not content: return {} # content = request.forms.content if ts.detect(content)['confidence'] == 's': content = convert2t(content) content = normyitizi(content) # stop_words = frozenset("不無一是有之者如法為故生此佛所三以二人云也於中若得心大") # content = ''.join(set(content)-stop_words) print(('content', content)) s = time.time() xx = fullsearch(content) # mq = qp.parse(content) # print(mq) # # mq = Term('content', content) # xx = [] # print('----------------------------------------') # with ix.searcher() as searcher: # # results = searcher.search(mq) # pageid = 1 # results = searcher.search_page(mq, pageid, pagelen=40) # # results = searcher.find(mq) # found = results.scored_length() # print(('found:', found)) # for hit in results: # hl = hit.highlights("content", top=5) # ct = hit["content"] # juan = hit["filename"].split('n')[0] # an = f'/xml/{juan}/{hit["filename"]}#{hit["p"]}' # xx.append((hl, an, hit['title'])) # pprint.pprint((hl, an)) e = time.time() print('----------------------------------------') print('搜索花费时间:%d' % (e - s)) print(xx) with open('search.dict', 'a+') as fd: fd.write(datetime.datetime.now().strftime("%Y%m%dT%T ") + content + '\n') return {'results': xx}
def jiantifanti(): content = request.GET.content if ts.detect(content)['confidence'] == 's': content = convert2t(content) return {'content': content}