From 3075f0ab8853fd97c68d3f0b8086dfa5c863c7f2 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 21 Jun 2018 18:23:09 -0700 Subject: copy some of paper-search over --- python/fatcat/routes.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'python/fatcat/routes.py') diff --git a/python/fatcat/routes.py b/python/fatcat/routes.py index f4c7c513..8fe74a2d 100644 --- a/python/fatcat/routes.py +++ b/python/fatcat/routes.py @@ -5,11 +5,11 @@ from flask import Flask, render_template, send_from_directory, request, \ url_for, abort, g, redirect, jsonify, session from fatcat import app, api from fatcat_client.rest import ApiException +from fatcat.search import do_search ### Views ################################################################### - @app.route('/container/', methods=['GET']) def container_view(ident): try: @@ -156,6 +156,32 @@ def editor_changelog(username): return render_template('editor_changelog.html', editor=editor, changelog_entries=changelog_entries) +### Search ################################################################## + +@app.route('/release/search', methods=['GET', 'POST']) +def search(): + + limit = 20 + query = request.args.get('q') + + # Convert raw DOIs to DOI queries + if query is not None: + oldquery = query.split() + for word in oldquery: + if word.startswith("10.") and word.count("/") >= 1: + query = query.replace(word, 'doi:"{}"'.format(word)) + + # Convert "author:" query to "authors:" + if query is not None: + query = query.replace("author:", "authors:") + + if 'q' in request.args.keys(): + # always do files for HTML + found = do_search(query, limit=limit) + return render_template('release_search.html', found=found) + else: + return render_template('release_search.html') + ### Static Routes ########################################################### -- cgit v1.2.3