2
0

api_search.py 1.1 KB

1234567891011121314151617181920212223242526272829
  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. # 개편 예정
  8. curs.execute(db_change('select data from other where name = "count_all_title"'))
  9. if int(curs.fetchall()[0][0]) < 30000:
  10. curs.execute(db_change("" + \
  11. "select distinct title, case " + \
  12. "when title like ? then 'title' else 'data' end from data " + \
  13. "where (title like ? or data like ?) order by case " + \
  14. "when title like ? then 1 else 2 end limit ?, ?"),
  15. ['%' + name + '%', '%' + name + '%', '%' + name + '%', '%' + name + '%', page, num]
  16. )
  17. else:
  18. curs.execute(db_change("select title from data where title like ? order by title limit ?, ?"),
  19. ['%' + name + '%', page, num]
  20. )
  21. all_list = curs.fetchall()
  22. if all_list:
  23. return flask.jsonify(all_list)
  24. else:
  25. return flask.jsonify({})