aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat/routes.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-06-21 18:23:09 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-06-21 18:23:09 -0700
commit3075f0ab8853fd97c68d3f0b8086dfa5c863c7f2 (patch)
tree5bb022e5dc1dc57cd663afc9feec33e6b5039bb1 /python/fatcat/routes.py
parent416117af51592b2a60b317427dc034544347b435 (diff)
downloadfatcat-3075f0ab8853fd97c68d3f0b8086dfa5c863c7f2.tar.gz
fatcat-3075f0ab8853fd97c68d3f0b8086dfa5c863c7f2.zip
copy some of paper-search over
Diffstat (limited to 'python/fatcat/routes.py')
-rw-r--r--python/fatcat/routes.py28
1 files changed, 27 insertions, 1 deletions
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/<uuid:ident>', 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 ###########################################################