A search interface for the Performing Patents Otherwise publication as part of the Politics of Patents case study (part of Copim WP6): this parses data from the archive of RTF files and provides additional data from the European Patent Office OPS API. https://patents.copim.ac.uk
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search.py 3.1KB

2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # @name: search.py
  2. # @creation_date: 2022-09-07
  3. # @license: The MIT License <https://opensource.org/licenses/MIT>
  4. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  5. # @purpose: search route for search
  6. # @acknowledgements:
  7. # https://www.digitalocean.com/community/tutorials/how-to-add-authentication-to-your-app-with-flask-login
  8. from flask import Blueprint, render_template, request, redirect, url_for
  9. from . import solr
  10. from . import ops
  11. search = Blueprint('search', __name__)
  12. # route for search page
  13. @search.route('/search/', methods=['GET', 'POST'])
  14. def basic_search():
  15. if request.method == 'POST':
  16. search = request.form.get('search')
  17. if request.form.get('core') is not None:
  18. core = request.form.get('core')
  19. else:
  20. core = 'all'
  21. if request.form.get('sort') is not None:
  22. sort = request.form.get('sort')
  23. else:
  24. sort = 'relevance'
  25. search_results = solr.content_search(core, sort, search)
  26. results = search_results[0]
  27. num_found = search_results[1]
  28. total_number = solr.get_total_number(core)
  29. return render_template('search.html', results=results, num_found=num_found, total_number=total_number, search=search, core=core, sort=sort)
  30. else:
  31. return redirect(url_for('main.index'))
  32. # route for id_search page
  33. @search.route('/search/id/', methods=['GET'])
  34. def id_search():
  35. if request.args.get('id') is None:
  36. return redirect(url_for('main.index'))
  37. else:
  38. id = request.args.get('id')
  39. if request.args.get('core') is not None:
  40. core = request.args.get('core')
  41. else:
  42. core = 'all'
  43. if request.args.get('sort') is not None:
  44. sort = request.args.get('sort')
  45. else:
  46. sort = 'relevance'
  47. search_results = solr.content_search(core, sort, search, id)
  48. results = search_results[0]
  49. for result in results:
  50. publication_details = ops.get_publication_details(result['doc_ref'])
  51. result.update(publication_details)
  52. if ops.get_images(result['doc_ref']):
  53. image = ops.get_images(result['doc_ref'])
  54. result.update(image)
  55. return render_template('record.html', results=results)
  56. # route for country search page
  57. @search.route('/search/country/', methods=['GET', 'POST'])
  58. def country_search():
  59. if request.method == 'POST':
  60. country_code = request.form.get('country_code')
  61. core = request.form.get('core')
  62. sort = request.form.get('sort')
  63. else:
  64. country_code = request.args.get('country_code')
  65. core = request.args.get('core')
  66. sort = request.args.get('sort')
  67. if country_code is None:
  68. return redirect(url_for('main.index'))
  69. if core is None:
  70. core = 'all'
  71. if sort is None:
  72. sort = 'relevance'
  73. search_results = solr.country_search(core, sort, country_code)
  74. results = search_results[0]
  75. num_found = search_results[1]
  76. total_number = solr.get_total_number(core)
  77. return render_template('search.html', results=results, num_found=num_found, total_number=total_number, country_code=country_code, core=core, sort=sort)