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.

55 line
1.8KB

  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. search_results = solr.solr_search(core, sort, search)
  25. results = search_results[0]
  26. num_found = search_results[1]
  27. return render_template('search.html', results=results, num_found=num_found, search=search, core=core, sort=sort)
  28. # route for id_search page
  29. @search.route('/search/id/')
  30. def id_search():
  31. if request.args.get('core') is not None:
  32. core = request.args.get('core')
  33. else:
  34. core = 'all'
  35. if request.args.get('sort') is not None:
  36. sort = request.args.get('sort')
  37. else:
  38. sort = 'relevance'
  39. id = request.args.get('id')
  40. search_results = solr.solr_search(core, sort, search, id)
  41. results = search_results[0]
  42. for result in results:
  43. publication_details = ops.get_publication_details(result['doc_ref'])
  44. result.update(publication_details)
  45. if ops.get_images(result['doc_ref']):
  46. image = ops.get_images(result['doc_ref'])
  47. result.update(image)
  48. return render_template('record.html', results=results)