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

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