From 608467fdd8ff66822eadec3ffa93ff12bbc365ac Mon Sep 17 00:00:00 2001 From: gauthiier Date: Thu, 9 Nov 2017 13:49:22 +0100 Subject: [PATCH] nbr. hits --- search/archive.py | 4 ++-- www/routes.py | 11 +++++++++-- www/templates/search.html | 5 +++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/search/archive.py b/search/archive.py index 8ce64df..fc35844 100644 --- a/search/archive.py +++ b/search/archive.py @@ -53,7 +53,7 @@ class Archive(): return nbr_hits - def search(self, keyword, field='content'): + def search(self, keyword, field='content', min_hits=0): search_results = { "keyword": keyword, "field": field, "archive": self.archive_name, "results": [] } @@ -68,7 +68,7 @@ class Archive(): nbr_hits += self.search_message(keyword, m, current_index_str, hits, field) i += 1 - if nbr_hits > 0: + if nbr_hits > min_hits: # nettime-l - fix (the name of the thread from ex. 'nettime-l_Jan_01' to 'January 2001') if k.startswith("nettime-l_"): dt = datetime.strptime(k, "nettime-l_%b_%y") diff --git a/www/routes.py b/www/routes.py index 257d7e4..d48492d 100644 --- a/www/routes.py +++ b/www/routes.py @@ -97,12 +97,13 @@ def searh(): if len(request.args) < 1: k = archives_data.keys() - return render_template("search.html", archives=k, fields=['content', 'from(name)', 'from(email)']) + return render_template("search.html", archives=k, fields=['content', 'from(name)', 'from(email)'], hits=['n/a', '2', '3', '4', '5', '6', '7', '8', '9']) k_arg = request.args.get('keyword') l_arg = request.args.get('list') sl_arg = request.args.get('sublist') f_arg = request.args.get('field') + h_arg = request.args.get('hits') if k_arg is None or k_arg.strip() == '': return "no keyword..." @@ -129,6 +130,12 @@ def searh(): else: lists.append(l_arg) + nbr_hits = 0 + if h_arg in ['2', '3', '4', '5', '6', '7', '8', '9']: + nbr_hits = int(h_arg) + + + ################################ ## ## need to cache all the below @@ -145,7 +152,7 @@ def searh(): # a = search.archive.Archive() # a.load(l) - results.append(archives_data[l].search(keyword=k_arg, field=f_arg)) + results.append(archives_data[l].search(keyword=k_arg, field=f_arg, min_hits=nbr_hits)) ## -- sort results? search_results = sorted(results, key=get_result_key) diff --git a/www/templates/search.html b/www/templates/search.html index c5b5715..a92048e 100644 --- a/www/templates/search.html +++ b/www/templates/search.html @@ -20,6 +20,11 @@ {% endfor %} +
Loading...