diff options
-rw-r--r-- | fatcat_covid19/search.py | 30 | ||||
-rw-r--r-- | fatcat_covid19/templates/fulltext_search.html | 70 | ||||
-rw-r--r-- | fatcat_covid19/webface.py | 8 |
3 files changed, 98 insertions, 10 deletions
diff --git a/fatcat_covid19/search.py b/fatcat_covid19/search.py index 82d5c60..7d4596d 100644 --- a/fatcat_covid19/search.py +++ b/fatcat_covid19/search.py @@ -71,13 +71,41 @@ def generic_search_execute(search, limit=25, offset=0, deep_page_limit=2000): "query_time_ms": int(resp.took), } -def do_fulltext_search(q, limit=25, offset=0): +def do_fulltext_search(q, limit=25, offset=0, filter_time=None, filter_type=None): # Convert raw DOIs to DOI queries if len(q.split()) == 1 and q.startswith("10.") and q.count("/") >= 1: q = 'doi:"{}"'.format(q) search = Search(using=app.es_client, index=app.config['ELASTICSEARCH_FULLTEXT_INDEX']) + + # type filters + if filter_type == "papers": + search = search.filter("terms", release_type=[ "article-journal", "paper-conference", ]) + elif filter_type == "reports": + search = search.filter("terms", release_type=[ "report", "standard", ]) + elif filter_type == "datasets": + search = search.filter("terms", release_type=[ "dataset", "software", ]) + elif filter_type == "everything" or filter_type == None: + pass + else: + abort(400) + + # time filters + if filter_time == "past_week": + week_ago_date = str(datetime.date.today() - datetime.timedelta(days=7)) + search = search.filter("range", release_date=dict(gte=week_ago_date)) + elif filter_time == "this_year": + search = search.filter("term", release_year=datetime.date.today().year) + elif filter_time == "since_2000": + search = search.filter("range", release_year=dict(gte=2000)) + elif filter_time == "before_1925": + search = search.filter("range", release_year=dict(lte=1924)) + elif filter_time == "all_time" or filter_time == None: + pass + else: + abort(400) + search = search.query( 'query_string', query=q, diff --git a/fatcat_covid19/templates/fulltext_search.html b/fatcat_covid19/templates/fulltext_search.html index 1d54f78..affb7b5 100644 --- a/fatcat_covid19/templates/fulltext_search.html +++ b/fatcat_covid19/templates/fulltext_search.html @@ -21,13 +21,63 @@ <input type="text" placeholder="{{ _("Query...") }}" name="q" value="{% if query %}{{ query }}{% endif %}" aria-label="search metadata"> <button class="ui primary 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> + + <br> + Include: + +{# + <div class="ui inline dropdown"> + <input type="hidden" name="filter_time"> + <div class="text">{{ filter_time or 'any' }}</div> + <i class="dropdown icon"></i> + <div class="menu"> + <div class="header"> + <i class="filter icon"></i> + Publication Stage + </div> + <div class="divider"></div> + <div class="{% if filter_type == 'any' %}active{% endif %} item" data-value="any" >{{ _("any stage") }}</div> + <div class="{% if filter_type == 'published' %}active{% endif %} item" data-value="published" >{{ _("only published") }}</div> + <div class="{% if filter_type == 'pre_print' %}active{% endif %} item" data-value="pre_print" >{{ _("only pre-print") }}</div> + </div> + </div> +#} + + <div class="ui inline dropdown"> + <input type="hidden" name="filter_type" value="{{ filter_type }}"> + <div class="text">{{ filter_type or "papers" }}</div> + <i class="dropdown icon"></i> + <div class="menu"> + <div class="header"> + <i class="filter icon"></i> + Resource Type + </div> + <div class="divider"></div> + <div class="{% if filter_type == 'papers' %}active{% endif %} item" data-value="papers" >{{ _("papers") }}</div> + <div class="{% if filter_type == 'reports' %}active{% endif %} item" data-value="reports" >{{ _("reports") }}</div> + <div class="{% if filter_type == 'datasets' %}active{% endif %} item" data-value="datasets" >{{ _("datasets") }}</div> + <div class="{% if filter_type == 'everything' %}active{% endif %} item" data-value="everything">{{ _("everything") }}</div> + </div> + </div> + + from + <div class="ui inline dropdown"> + <input type="hidden" name="filter_time" vale="{{ filter_time }}"> + <div class="text">{{ filter_time or "all time" }}</div> + <i class="dropdown icon"></i> + <div class="menu"> + <div class="header"> + <i class="filter icon"></i> + Time Period + </div> + <div class="divider"></div> + <div class="{% if filter_type == 'all' %}active{% endif %} item" data-value="all" >{{ _("all time") }}</div> + <div class="{% if filter_type == 'past_week' %}active{% endif %} item" data-value="past_week" >{{ _("past week") }}</div> + <div class="{% if filter_type == 'this_year' %}active{% endif %} item" data-value="this_year" >{{ _("this year") }}</div> + <div class="{% if filter_type == 'since_2000' %}active{% endif %} item" data-value="since_2000" >{{ _("since 2000") }}</div> + <div class="{% if filter_type == 'before_1925' %}active{% endif %} item" data-value="before_1925">{{ _("before 1925") }}</div> + </div> </div> - <br>Can also lookup by <b><a href="/release/lookup">identifier</a></b> or search for <b><a href="/container/search?q={{ query or "" }}">containers</a></b> (eg, journals). - #} </div> </form> </div> @@ -89,3 +139,11 @@ {% endif %} {% endblock %} + +{% block postscript %} +<script> +$('.ui.inline.dropdown') + .dropdown() +; +</script> +{% endblock %} diff --git a/fatcat_covid19/webface.py b/fatcat_covid19/webface.py index 662a2f0..aa604df 100644 --- a/fatcat_covid19/webface.py +++ b/fatcat_covid19/webface.py @@ -83,15 +83,17 @@ def page_home(): def fulltext_search(): query = request.args.get('q') + filter_type = request.args.get('filter_type') or None + filter_time = request.args.get('filter_time') or None offset = request.args.get('offset', '0') offset = max(0, int(offset)) if offset.isnumeric() else 0 if 'q' in request.args.keys(): - found = do_fulltext_search(query, offset=offset) - return render_template('fulltext_search.html', found=found, query=query) + found = do_fulltext_search(query, offset=offset, filter_type=filter_type, filter_time=filter_time) + return render_template('fulltext_search.html', found=found, query=query, filter_type=filter_type, filter_time=filter_time) else: - return render_template('fulltext_search.html', query=query) + return render_template('fulltext_search.html', query=query, filter_type=filter_type, filter_time=filter_time) @bp.route('/about', methods=['GET']) def page_about(): |