def search(request): hit = 15 #每页结果数 os = SearchAPI() kw = request.GET.get('keywords').encode('utf-8') if kw == "": return HttpResponse("关键字不能为空!<a href=\"../index\">返回</a>") page = helper.get_page( request.GET.get('page') ) start = (page - 1) * hit helper.save_search_log(kw, page) res = os.search(kw, start, hit) if res is None: return HttpResponse("内部错误,请联系 砺诚") num = res['num'] nextPage = page + 1 if not (res['total'] > page * hit): nextPage = 0 prePage = page -1 f = open("mysite/result.html") t = template.Template(f.read()) for item in res['items']: item['id'] = int(item['id']) c = template.Context({ "keyword":kw, "all_result":res['items'], "total":res['total'], "num":res['num'], "searchtime":res['searchtime'], "page":page, "nextPage":nextPage, "prePage":prePage }) return HttpResponse(t.render(c))
def search(request): hit = 15 #每页结果数 os = SearchAPI() kw = request.GET.get('keywords').encode('utf-8') if kw == "": return HttpResponse("关键字不能为空!<a href=\"../index\">返回</a>") page = helper.get_page(request.GET.get('page')) start = (page - 1) * hit helper.save_search_log(kw, page) res = os.search(kw, start, hit) if res is None: return HttpResponse("内部错误,请联系 砺诚") num = res['num'] nextPage = page + 1 if not (res['total'] > page * hit): nextPage = 0 prePage = page - 1 f = open("mysite/result.html") t = template.Template(f.read()) for item in res['items']: item['id'] = int(item['id']) c = template.Context({ "keyword": kw, "all_result": res['items'], "total": res['total'], "num": res['num'], "searchtime": res['searchtime'], "page": page, "nextPage": nextPage, "prePage": prePage }) return HttpResponse(t.render(c))
def search(request): hit = 15 #每页结果数 kw = request.GET.get('keywords').encode('utf-8') if kw == "": return HttpResponse("关键字不能为空!<a href=\"../index\">返回</a>") page = helper.get_page( request.GET.get('page') ) start = (page - 1) * hit helper.save_search_log(kw, page) res = searcher.search(kw.replace("'",""), start, hit, WEB_TAG) if res is None: return HttpResponse("内部错误,请联系 砺诚") num = res['num'] nextPage = page + 1 if not (res['total'] > page * hit): nextPage = 0 prePage = page -1 helper.save_search_result_info(kw, res['total']) f = open(search_page_template) t = template.Template(f.read()) for item in res['items']: item['id'] = int(item['id']) c = template.Context({ "keyword":kw, "all_result":res['items'], "total":res['total'], "num":res['num'], "searchtime":res['searchtime'], "page":page, "nextPage":nextPage, "prePage":prePage, "urlPrefix":URL_PREFIX }) return HttpResponse(t.render(c))