main_search_deep.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from .tool.func import *
  2. def main_search_deep(name = 'Test'):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. if name == '':
  6. return redirect()
  7. num = int(number_check(flask.request.args.get('num', '1')))
  8. sql_num = (num * 50 - 50) if num * 50 > 0 else 0
  9. div = '<ul class="inside_ul">'
  10. div_plus = ''
  11. test = ''
  12. curs.execute(db_change("select title from data where title = ?"), [name])
  13. link_id = '' if curs.fetchall() else 'id="not_thing"'
  14. div = '''
  15. <ul class="inside_ul">
  16. <li>
  17. <a ''' + link_id + ' href="/w/' + url_pas(name) + '">' + html.escape(name) + '''</a>
  18. </li>
  19. </ul>
  20. <hr class="main_hr">
  21. <ul class="inside_ul">
  22. '''
  23. curs.execute(db_change('select data from other where name = "count_all_title"'))
  24. if int(curs.fetchall()[0][0]) < 30000:
  25. curs.execute(db_change("" + \
  26. "select distinct title, case " + \
  27. "when title like ? then 'title' else 'data' end from data " + \
  28. "where (title like ? or data like ?) order by case " + \
  29. "when title like ? then 1 else 2 end limit ?, 50"),
  30. ['%' + name + '%', '%' + name + '%', '%' + name + '%', '%' + name + '%', sql_num]
  31. )
  32. all_list = curs.fetchall()
  33. if all_list:
  34. test = all_list[0][1]
  35. for data in all_list:
  36. if data[1] != test:
  37. div_plus += '</ul><hr class="main_hr"><ul class="inside_ul">'
  38. test = data[1]
  39. div_plus += '<li><a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a> (' + data[1] + ')</li>'
  40. else:
  41. curs.execute(db_change("select title from data where title like ? order by title limit ?, 50"),
  42. ['%' + name + '%', sql_num]
  43. )
  44. all_list = curs.fetchall()
  45. for data in all_list:
  46. div_plus += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (title)</li>'
  47. div += div_plus + '</ul>'
  48. div += next_fix('/search/' + url_pas(name) + '?num=', num, all_list)
  49. return easy_minify(flask.render_template(skin_check(),
  50. imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('search') + ')', 0])],
  51. data = div,
  52. menu = 0
  53. ))