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 1.7KB

2 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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
  9. from . import solr
  10. from . import ops
  11. search = Blueprint('search', __name__)
  12. # route for search page
  13. @search.route('/search/', methods=['POST'])
  14. def basic_search():
  15. search = request.form.get('search')
  16. if request.form.get('core') is not None:
  17. core = request.form.get('core')
  18. else:
  19. core = 'all'
  20. if request.form.get('sort') is not None:
  21. sort = request.form.get('sort')
  22. else:
  23. sort = 'relevance'
  24. results = solr.solr_search(core, sort, search)
  25. return render_template('search.html', results=results, search=search, core=core, sort=sort)
  26. # route for id_search page
  27. @search.route('/search/id/')
  28. def id_search():
  29. if request.args.get('core') is not None:
  30. core = request.args.get('core')
  31. else:
  32. core = 'all'
  33. if request.args.get('sort') is not None:
  34. sort = request.args.get('sort')
  35. else:
  36. sort = 'relevance'
  37. id = request.args.get('id')
  38. results = solr.solr_search(core, sort, search, id)
  39. for result in results:
  40. publication_details = ops.get_publication_details(result['doc_ref'])
  41. result.update(publication_details)
  42. if ops.get_images(result['doc_ref']):
  43. image = ops.get_images(result['doc_ref'])
  44. result.update(image)
  45. return render_template('record.html', results=results)