From c538d614819fff471cff821adfa302b563c87a2f Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 3 Oct 2018 14:17:50 -0700 Subject: improve search UI --- python/fatcat/routes.py | 11 +++++--- python/fatcat/search.py | 8 ++++-- python/fatcat/templates/release_search.html | 40 +++++++++++++++++++---------- 3 files changed, 41 insertions(+), 18 deletions(-) (limited to 'python') diff --git a/python/fatcat/routes.py b/python/fatcat/routes.py index ad5faea6..7e52f651 100644 --- a/python/fatcat/routes.py +++ b/python/fatcat/routes.py @@ -312,6 +312,7 @@ def search(): limit = 20 query = request.args.get('q') + fulltext_only = bool(request.args.get('fulltext_only')) # Convert raw DOIs to DOI queries if query is not None: @@ -322,10 +323,10 @@ def search(): 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) + found = do_search(query, limit=limit, fulltext_only=fulltext_only) + return render_template('release_search.html', found=found, query=query, fulltext_only=fulltext_only) else: - return render_template('release_search.html') + return render_template('release_search.html', query=query, fulltext_only=fulltext_only) ### Static Routes ########################################################### @@ -342,6 +343,10 @@ def homepage(): def aboutpage(): return render_template('about.html') +@app.route('/search', methods=['GET']) +def search_redirect(): + return redirect("/release/search") + @app.route('/robots.txt', methods=['GET']) def robots(): return send_from_directory(os.path.join(app.root_path, 'static'), diff --git a/python/fatcat/search.py b/python/fatcat/search.py index c179b12e..b6826110 100644 --- a/python/fatcat/search.py +++ b/python/fatcat/search.py @@ -4,13 +4,16 @@ from flask import abort from fatcat import app -def do_search(q, limit=20): +def do_search(q, limit=50, fulltext_only=True): #print("Search hit: " + q) if limit > 100: # Sanity check limit = 100 + if fulltext_only: + q += " file_in_ia:true" + search_request = { "query": { "query_string": { @@ -20,11 +23,12 @@ def do_search(q, limit=20): "analyze_wildcard": True, "lenient": True, "fields": ["title^5", "contrib_names^2", "container_title"] - } + }, }, "size": int(limit), } + #print(search_request) resp = requests.get("%s/%s/_search" % (app.config['ELASTIC_BACKEND'], app.config['ELASTIC_INDEX']), json=search_request) diff --git a/python/fatcat/templates/release_search.html b/python/fatcat/templates/release_search.html index 800d550e..c57ad149 100644 --- a/python/fatcat/templates/release_search.html +++ b/python/fatcat/templates/release_search.html @@ -1,9 +1,25 @@ {% extends "base.html" %} {% block body %} +

Article Search

+
+
+
+ + +
+
+ + +
+
+
+ +
+ {% if found %} -

Search Results

-Showing top {{ found.count_returned }} out of {{ found.count_found }} results for: {{ found.query.q }} +{% if found.results %} + Showing top {{ found.count_returned }} out of {{ found.count_found }} results for: {{ found.query.q }} {% for paper in found.results %}

{{ paper['title'] }} @@ -29,22 +45,20 @@ {% if paper.container_is_oa %}{% endif %} {% endif %}

+{% endfor %} {% else %} -
-

Try:

- {% endif %} +{% endif %} {% endblock %} -- cgit v1.2.3