2
0

api_search.py 1.1 KB

12345678910111213141516171819202122232425262728
  1. from .tool.func import *
  2. def api_search(name = 'Test', num = 10, page = 1):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. num = 1 if num > 1000 else num
  6. page = (page * (num - 1)) if page * num > 0 else 0
  7. curs.execute(db_change('select data from other where name = "count_all_title"'))
  8. if int(curs.fetchall()[0][0]) < 30000:
  9. curs.execute(db_change("" + \
  10. "select distinct title, case " + \
  11. "when title like ? then 'title' else 'data' end from data " + \
  12. "where (title like ? or data like ?) order by case " + \
  13. "when title like ? then 1 else 2 end limit ?, ?"),
  14. ['%' + name + '%', '%' + name + '%', '%' + name + '%', '%' + name + '%', page, num]
  15. )
  16. else:
  17. curs.execute(db_change("select title from data where title like ? order by title limit ?, ?"),
  18. ['%' + name + '%', page, num]
  19. )
  20. all_list = curs.fetchall()
  21. if all_list:
  22. return flask.jsonify(all_list)
  23. else:
  24. return flask.jsonify({})