From 5bc77c47eed20676cd3db162c9675311f77c6cf9 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 9 Feb 2022 00:24:46 -0800 Subject: web: move search-in-container to dedicated tab --- python/fatcat_web/templates/entity_base.html | 1 + 1 file changed, 1 insertion(+) (limited to 'python/fatcat_web/templates/entity_base.html') diff --git a/python/fatcat_web/templates/entity_base.html b/python/fatcat_web/templates/entity_base.html index c3d6096b..2782edd5 100644 --- a/python/fatcat_web/templates/entity_base.html +++ b/python/fatcat_web/templates/entity_base.html @@ -83,6 +83,7 @@ {{ entity_tab("overview", "Overview", "") }} {% if entity_type == "container" and entity.state == 'active' and not editgroup %} {{ entity_tab("coverage", "Preservation", "/coverage") }} + {{ entity_tab("search", "Search", "/search") }} {% elif entity_type == "release" and entity.state != 'deleted' %} {{ entity_tab("contribs", "Authors", "/contribs", entity._authors|count ) }} {% if entity.state == 'active' %} -- cgit v1.2.3 From d73ab1f7cc45c122f321f0e717de2067554baabb Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 9 Feb 2022 17:16:11 -0800 Subject: containers: initial work on 'browse' feature --- python/fatcat_web/routes.py | 11 +++- python/fatcat_web/search.py | 64 ++++++++++++++++++++++ .../templates/container_view_browse.html | 32 +++++++++++ python/fatcat_web/templates/entity_base.html | 1 + 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 python/fatcat_web/templates/container_view_browse.html (limited to 'python/fatcat_web/templates/entity_base.html') diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py index b25cd37c..9f46c674 100644 --- a/python/fatcat_web/routes.py +++ b/python/fatcat_web/routes.py @@ -60,6 +60,7 @@ from fatcat_web.search import ( ReleaseQuery, do_container_search, do_release_search, + get_elastic_container_browse_year_volume, get_elastic_container_histogram_legacy, get_elastic_container_preservation_by_volume, get_elastic_container_random_releases, @@ -286,6 +287,8 @@ def generic_entity_view(entity_type: str, ident: str, view_template: str) -> Any entity._type_preservation = get_elastic_preservation_by_type( ReleaseQuery(container_id=ident), ) + if view_template == "container_view_browse.html": + entity._browse_volume_year = get_elastic_container_browse_year_volume(entity.ident) return render_template( view_template, entity_type=entity_type, entity=entity, editgroup_id=None @@ -346,6 +349,12 @@ def container_view_coverage(ident: str) -> AnyResponse: return generic_entity_view("container", ident, "container_view_coverage.html") +@app.route("/container//browse", methods=["GET"]) +def container_view_browser(ident: str) -> AnyResponse: + # note: there is a special hack to add entity._type_preservation for this endpoint + return generic_entity_view("container", ident, "container_view_browse.html") + + @app.route("/container//metadata", methods=["GET"]) def container_view_metadata(ident: str) -> AnyResponse: return generic_entity_view("container", ident, "entity_view_metadata.html") @@ -1079,7 +1088,7 @@ def coverage_search() -> AnyResponse: ) -@app.route("/container//search", methods=["GET", "POST"]) +@app.route("/container//search", methods=["GET", "POST"]) def container_view_search(ident: str) -> AnyResponse: entity = generic_get_entity("container", ident) diff --git a/python/fatcat_web/search.py b/python/fatcat_web/search.py index 9e9376cc..ac4dc34e 100644 --- a/python/fatcat_web/search.py +++ b/python/fatcat_web/search.py @@ -327,6 +327,70 @@ def get_elastic_container_random_releases(ident: str, limit: int = 5) -> List[Di return results +def get_elastic_container_browse_year_volume(ident: str) -> List[Dict[int, Any]]: + """ + Returns a set of histogram buckets: + + container_ident: str + years{} + volumes{} + """ + + search = Search(using=app.es_client, index=app.config["ELASTICSEARCH_RELEASE_INDEX"]) + search = search.query( + "bool", + filter=[Q("bool", must_not=[Q("match", release_type="stub")])], + ) + search = search.filter("term", container_id=ident) + search.aggs.bucket( + "year_volume", + "composite", + size=1500, + sources=[ + { + "year": { + "histogram": { + "field": "release_year", + "interval": 1, + "missing_bucket": True, + # TODO: es-public-proxy support? + # "order": "asc", + # "missing_order": "last", + }, + } + }, + { + "volume": { + "terms": { + "field": "volume", + "missing_bucket": True, + # TODO: es-public-proxy support? + # "order": "asc", + # "missing_order": "last", + }, + } + }, + ], + ) + search = search[:0] + search = search.params(request_cache=True) + resp = wrap_es_execution(search) + buckets = resp.aggregations.year_volume.buckets + # print(buckets) + buckets = [h for h in buckets if h["key"]["year"]] + year_nums = set([int(h["key"]["year"]) for h in buckets]) + year_dicts: Dict[int, Dict[str, Any]] = dict() + if year_nums: + for year in year_nums: + year_dicts[year] = {} + for row in buckets: + year_dicts[int(row["key"]["year"])][row["key"]["volume"] or "_unknown"] = int( + row["doc_count"] + ) + # return sorted(year_dicts.values(), key=lambda x: x["year"]) + return year_dicts + + def get_elastic_entity_stats() -> dict: """ TODO: files, filesets, webcaptures (no schema yet) diff --git a/python/fatcat_web/templates/container_view_browse.html b/python/fatcat_web/templates/container_view_browse.html new file mode 100644 index 00000000..b5691899 --- /dev/null +++ b/python/fatcat_web/templates/container_view_browse.html @@ -0,0 +1,32 @@ +{% set container = entity %} +{% set entity_view = "browse" %} +{% set entity_type = "container" %} +{% import "entity_macros.html" as entity_macros %} +{% extends "entity_base.html" %} + +{% block entity_main %} + +{% if entity._browse_volume_year %} +

Browse by Year and Volume

+
    +{% for year in entity._browse_volume_year.keys()|sort|reverse %} + {% for volume in entity._browse_volume_year[year].keys()|sort|reverse %} + {% if volume == '_unknown' %} +
  • {{ year }} ({{ entity._browse_volume_year[year][volume] }} releases) + {% else %} +
  • {{ year }} | Vol. {{ volume }} ({{ entity._browse_volume_year[year][volume] }} releases) + {% endif %} + {% endfor %} +{% endfor %} +
+{% elif entity._browse_issues %} +{% for issue in entity._browse_issues.keys()|sort|reverse %} +

{{ issue }}

+ {% for paper in entity._browse_issues[issue] %} + {{ paper.title }}
+ {% endfor %} +{% endfor %} +{% endif %} + +{% endblock %} + diff --git a/python/fatcat_web/templates/entity_base.html b/python/fatcat_web/templates/entity_base.html index 2782edd5..633f3aee 100644 --- a/python/fatcat_web/templates/entity_base.html +++ b/python/fatcat_web/templates/entity_base.html @@ -82,6 +82,7 @@ {% endif %} @@ -102,17 +119,22 @@
{% if container.issnl != None %} ISSN-L? -  {{ container.issnl }} +  {{ container.issnl }}
{% endif %} {% if container.issnp or (container.extra != None and container.extra.issnp != None and (container.extra.issnp|length > 0)) %} -
Print:  {{ container.issnp or container.extra.issnp }} +     Print:  {{ container.issnp or container.extra.issnp }}
{% endif %} {% if container.issne or (container.extra != None and container.extra.issne != None and (container.extra.issne|length > 0)) %} -
Electronic:  {{ container.issne or container.extra.issne }} +     Electronic:  {{ container.issne or container.extra.issne }}
{% endif %} -
{% if container.wikidata_qid != None %} - Wikidata  {{ container.wikidata_qid }} + Wikidata  {{ container.wikidata_qid }}
+ {% endif %} + {% if container.extra and container.extra.dblp %} + dblp  {{ container.extra.dblp.prefix }}
+ {% endif %} + {% if container.extra and container.extra.ia and container.extra.ia.sim %} + archive.org  sim_pubid:{{ container.extra.ia.sim.sim_pubid }}
{% endif %}
{% endif %} @@ -128,23 +150,15 @@ {% if container._es.in_road == True %} In ISSN ROAD
- {% elif container._es.in_road == False %} - Not in ISSN ROAD
- {% endif %} - - {% if container._es.any_kbart == True %} - In Keepers Registery -
- {% elif container._es.any_kbart == False %} - Not in Keepers Registry
{% endif %} - {% if container.extra and container.extra.sherpa_romeo and container.extra.sherpa_romeo.color %} - SHERPA/RoMEO color: {{ container.extra.sherpa_romeo.color }} + {% if container.extra and container.extra.szczepanski %} + In Szczepanski List
{% endif %} {% endif %} +{# {%- if container.extra and container.extra.kbart %}
Preservation Holdings
@@ -175,6 +189,7 @@ {% endfor %}
{% endif %} +#}
Lookup Links
diff --git a/python/fatcat_web/templates/entity_base.html b/python/fatcat_web/templates/entity_base.html index 633f3aee..626c102a 100644 --- a/python/fatcat_web/templates/entity_base.html +++ b/python/fatcat_web/templates/entity_base.html @@ -75,6 +75,10 @@ {% endif %}
{% endif %} + {% elif entity_type == "container" %} + {% if entity.publisher %} +

{{ entity.publisher }} + {% endif %} {% endif %}

-- cgit v1.2.3