aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-10-03 14:17:50 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-10-03 14:17:50 -0700
commitc538d614819fff471cff821adfa302b563c87a2f (patch)
treee9ff1e1f736ec1400020471f79fbe2e5bad97674 /python
parent9623cd35e5342f8ec9b6052261f4d0bc3094dedc (diff)
downloadfatcat-c538d614819fff471cff821adfa302b563c87a2f.tar.gz
fatcat-c538d614819fff471cff821adfa302b563c87a2f.zip
improve search UI
Diffstat (limited to 'python')
-rw-r--r--python/fatcat/routes.py11
-rw-r--r--python/fatcat/search.py8
-rw-r--r--python/fatcat/templates/release_search.html40
3 files changed, 41 insertions, 18 deletions
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 %}
+<h1>Article Search</h1>
+<form class="" role="search" action="/release/search" method="get">
+ <div class="ui form">
+ <div class="ui action input huge fluid">
+ <input type="text" placeholder="Query..." name="q" value="{% if query %}{{ query }}{% endif %}">
+ <button class="ui button">Search</button>
+ </div>
+ <div class="ui checkbox" style="float: right; margin: 1em;">
+ <input type="checkbox" name="fulltext_only" value="true" {% if fulltext_only %}checked{% endif %}>
+ <label>Fulltext Available Only</label>
+ </div>
+ </div>
+</form>
+
+<br clear="all" />
+
{% if found %}
-<h1>Search Results</h1>
-<i>Showing top {{ found.count_returned }} out of {{ found.count_found }} results for: <code>{{ found.query.q }}</code></i>
+{% if found.results %}
+ <i>Showing top {{ found.count_returned }} out of {{ found.count_found }} results for: <code>{{ found.query.q }}</code></i>
{% for paper in found.results %}
<div>
<h4 style="margin-top: 1em; margin-bottom: 4px; font-size: 1.1em;"><a href="/release/lookup?doi={{ paper.doi }}" style="color: #2224c7;">{{ paper['title'] }}</a>
@@ -29,22 +45,20 @@
{% if paper.container_is_oa %}<i class="icon unlock orange small"></i>{% endif %}
{% endif %}
</div>
+{% endfor %}
{% else %}
-<br/>
-<p>Try:</p>
-<ul>
+<div class="featurette-inner text-center" style="padding-top: 15%;">
+ <h3>No results found!</h3>
+ <i>Query was: <code>{{ found.query.q }}</code></i>
+ <br/>
+ <p>Try:</p>
+ <ul>
<li>Search <a href="https://dissem.in/search?q={{ found.query.q | urlencode }}">dissem.in</a></li>
<li>Search <a href="https://www.base-search.net/Search/Results?lookfor={{ found.query.q | urlencode }}">BASE</a></li>
<li>Search <a href="https://scholar.google.com/scholar?q={{ found.query.q | urlencode }}">Google Scholar</a></li>
-</ul>
-<div class="featurette-inner text-center" style="padding-top: 25%;">
-<h3>Found nothing!</h3>
-</div>
-{% endfor %}
-{% else %}
-<div class="featurette-inner text-center" style="padding-top: 25%;">
-<h3>Enter a query above</h3>
+ </ul>
</div>
{% endif %}
+{% endif %}
{% endblock %}