From 2a7f359e66b3eccea41314b1bd98a640ec5f5b43 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: May 23 2021 21:51:44 +0000 Subject: add basic pagination and result count to search --- diff --git a/bin/search-uwsgi.py b/bin/search-uwsgi.py index fbc2571..795da1d 100755 --- a/bin/search-uwsgi.py +++ b/bin/search-uwsgi.py @@ -24,11 +24,18 @@ def application(params, start_response): start_response('500 Internal Server Error', [('Content-Type','text/html')]) return [b'Error: No query string'] d = parse_qs(query_str) + query = d.get('query', [''])[0] query = quote(query) try: - query_res = get(f"{SOLR_URL}solr/{SOLR_CORE}/select?defType=simple&q={query}") + start = d.get('start', [''])[0] + start = int(start) + except: + start = 0 + + try: + query_res = get(f"{SOLR_URL}solr/{SOLR_CORE}/select?defType=simple&start={start}&q={query}") except: print("Solr request error: ", str(exc_info()[0])) start_response('500 Internal Server Error', [('Content-Type','text/html')]) diff --git a/templates/search-results.html.j2 b/templates/search-results.html.j2 index 9d5a26d..7655ab9 100644 --- a/templates/search-results.html.j2 +++ b/templates/search-results.html.j2 @@ -34,8 +34,6 @@
- - {% if results['spellcheck'] and results.spellcheck.collations[1] %}

Did you mean @@ -47,6 +45,10 @@

No results found!

+ {% elif results.response.numFound > 1 %} +
+

{{ results.response.numFound }} results found

+
{% endif %} {% for result in results.response.docs %} @@ -58,6 +60,17 @@

{{ result.description }}

{% endfor %} + + {% if results.response.numFound > 10 %} +
+ {% if results['responseHeader']['params']['start']|int >= 10 %} + « Previous Page + {% endif %} + {% if results.response.numFound - results['responseHeader']['params']['start']|int > 10 %} + Next Page » + {% endif %} +
+ {% endif %}