forked from zaclys/searxng
[enh] paging support
This commit is contained in:
parent
93b5ecdc75
commit
8bb94e3dc4
|
@ -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(
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -11,10 +11,6 @@
|
|||
{% endif %}
|
||||
|
||||
|
||||
<div id ="result_count">
|
||||
{{ _('Number of results') }}: {{ number_of_results }}
|
||||
</div>
|
||||
|
||||
{% 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 %}
|
||||
<div id="paging">
|
||||
{% if pageno > 1 %}
|
||||
<form method="post" action="/">
|
||||
<div class="left">
|
||||
<input type="hidden" name="q" value="{{ q }}" />
|
||||
<input type="hidden" name="pageno" value="{{ pageno-1 }}" />
|
||||
<input type="submit" value="<< {{ _('previous page') }}" />
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
<form method="post" action="/">
|
||||
<div class="left">
|
||||
<input type="hidden" name="q" value="{{ q }}" />
|
||||
<input type="hidden" name="pageno" value="{{ pageno+1 }}" />
|
||||
<input type="submit" value="{{ _('next page') }} >>" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div id="apis">
|
||||
{{ _('Download results') }}
|
||||
<form method="post" action="/">
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue