From 8bb94e3dc4c35042ec5fb16f412331f4b8ca6c8a Mon Sep 17 00:00:00 2001 From: asciimoo Date: Wed, 29 Jan 2014 20:52:04 +0100 Subject: [PATCH] [enh] paging support --- searx/engines/__init__.py | 8 +++++++- searx/static/css/style.css | 2 -- searx/templates/results.html | 26 ++++++++++++++++++++++---- searx/webapp.py | 15 ++++++++++++--- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 96b074ae9..73a63f0a3 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -53,6 +53,8 @@ if not 'engines' in settings or not settings['engines']: for engine_data in settings['engines']: engine_name = engine_data['engine'] engine = load_module(engine_name + '.py') + if not hasattr(engine, 'paging'): + engine.paging = False for param_name in engine_data: if param_name == 'engine': continue @@ -156,7 +158,7 @@ def score_results(results): return sorted(results, key=itemgetter('score'), reverse=True) -def search(query, request, selected_engines): +def search(query, request, selected_engines, pageno=1): global engines, categories, number_of_searches requests = [] results = {} @@ -171,10 +173,14 @@ def search(query, request, selected_engines): engine = engines[selected_engine['name']] + if pageno > 1 and not engine.paging: + continue + request_params = default_request_params() request_params['headers']['User-Agent'] = user_agent request_params['category'] = selected_engine['category'] request_params['started'] = datetime.now() + request_params['pageno'] = pageno request_params = engine.request(query, request_params) callback = make_callback( diff --git a/searx/static/css/style.css b/searx/static/css/style.css index de831e382..a6e76b726 100644 --- a/searx/static/css/style.css +++ b/searx/static/css/style.css @@ -151,8 +151,6 @@ tr:hover td { background: #DDDDDD; } #results { margin: 10px; padding: 0; } -#result_count { font-size: 0.8em; margin: 2px 0 2px 0; padding: 0 } - #suggestions { position: absolute; left: 54em; width: 12em; margin: 0 2px 5px 5px; padding: 0 2px 2px 2px; } #suggestions span { display: block; font-size: 0.8em; margin: 0 2px 10px 2px; padding: 0; } #suggestions form { display: block; } diff --git a/searx/templates/results.html b/searx/templates/results.html index 238671878..fc5527296 100644 --- a/searx/templates/results.html +++ b/searx/templates/results.html @@ -11,10 +11,6 @@ {% endif %} -
- {{ _('Number of results') }}: {{ number_of_results }} -
- {% for result in results %} {% if result['template'] %} {% include 'result_templates/'+result['template'] %} @@ -22,6 +18,28 @@ {% include 'result_templates/default.html' %} {% endif %} {% endfor %} + + {% if paging %} +
+ {% if pageno > 1 %} +
+
+ + + +
+
+ {% endif %} +
+
+ + + +
+
+
+ {% endif %} +
{{ _('Download results') }}
diff --git a/searx/webapp.py b/searx/webapp.py index de1b8d56f..6f9d1745e 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -129,7 +129,7 @@ def parse_query(query): @app.route('/', methods=['GET', 'POST']) def index(): - global categories + paging = False if request.method == 'POST': request_data = request.form @@ -138,6 +138,12 @@ def index(): if not request_data.get('q'): return render('index.html') + pageno_param = request_data.get('pageno', '1') + if not pageno_param.isdigit() or int(pageno_param) < 1: + return render('index.html') + + pageno = int(pageno_param) + selected_categories = [] query, selected_engines = parse_query(request_data['q'].encode('utf-8')) @@ -166,10 +172,12 @@ def index(): 'name': x.name} for x in categories[categ]) - results, suggestions = search(query, request, selected_engines) + results, suggestions = search(query, request, selected_engines, pageno) featured_results = [] for result in results: + if not paging and engines[result['engine']].paging: + paging = True if request_data.get('format', 'html') == 'html': if 'content' in result: result['content'] = highlight_content(result['content'], query) @@ -219,7 +227,8 @@ def index(): results=results, q=request_data['q'], selected_categories=selected_categories, - number_of_results=len(results) + len(featured_results), + paging=paging, + pageno=pageno, featured_results=featured_results, suggestions=suggestions )