mirror of
https://github.com/searxng/searxng.git
synced 2024-12-29 20:50:28 +00:00
[enh] paging support
This commit is contained in:
parent
93b5ecdc75
commit
8bb94e3dc4
4 changed files with 41 additions and 10 deletions
|
@ -53,6 +53,8 @@ if not 'engines' in settings or not settings['engines']:
|
||||||
for engine_data in settings['engines']:
|
for engine_data in settings['engines']:
|
||||||
engine_name = engine_data['engine']
|
engine_name = engine_data['engine']
|
||||||
engine = load_module(engine_name + '.py')
|
engine = load_module(engine_name + '.py')
|
||||||
|
if not hasattr(engine, 'paging'):
|
||||||
|
engine.paging = False
|
||||||
for param_name in engine_data:
|
for param_name in engine_data:
|
||||||
if param_name == 'engine':
|
if param_name == 'engine':
|
||||||
continue
|
continue
|
||||||
|
@ -156,7 +158,7 @@ def score_results(results):
|
||||||
return sorted(results, key=itemgetter('score'), reverse=True)
|
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
|
global engines, categories, number_of_searches
|
||||||
requests = []
|
requests = []
|
||||||
results = {}
|
results = {}
|
||||||
|
@ -171,10 +173,14 @@ def search(query, request, selected_engines):
|
||||||
|
|
||||||
engine = engines[selected_engine['name']]
|
engine = engines[selected_engine['name']]
|
||||||
|
|
||||||
|
if pageno > 1 and not engine.paging:
|
||||||
|
continue
|
||||||
|
|
||||||
request_params = default_request_params()
|
request_params = default_request_params()
|
||||||
request_params['headers']['User-Agent'] = user_agent
|
request_params['headers']['User-Agent'] = user_agent
|
||||||
request_params['category'] = selected_engine['category']
|
request_params['category'] = selected_engine['category']
|
||||||
request_params['started'] = datetime.now()
|
request_params['started'] = datetime.now()
|
||||||
|
request_params['pageno'] = pageno
|
||||||
request_params = engine.request(query, request_params)
|
request_params = engine.request(query, request_params)
|
||||||
|
|
||||||
callback = make_callback(
|
callback = make_callback(
|
||||||
|
|
|
@ -151,8 +151,6 @@ tr:hover td { background: #DDDDDD; }
|
||||||
|
|
||||||
#results { margin: 10px; padding: 0; }
|
#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 { 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 span { display: block; font-size: 0.8em; margin: 0 2px 10px 2px; padding: 0; }
|
||||||
#suggestions form { display: block; }
|
#suggestions form { display: block; }
|
||||||
|
|
|
@ -11,10 +11,6 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
<div id ="result_count">
|
|
||||||
{{ _('Number of results') }}: {{ number_of_results }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% for result in results %}
|
{% for result in results %}
|
||||||
{% if result['template'] %}
|
{% if result['template'] %}
|
||||||
{% include 'result_templates/'+result['template'] %}
|
{% include 'result_templates/'+result['template'] %}
|
||||||
|
@ -22,6 +18,28 @@
|
||||||
{% include 'result_templates/default.html' %}
|
{% include 'result_templates/default.html' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% 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">
|
<div id="apis">
|
||||||
{{ _('Download results') }}
|
{{ _('Download results') }}
|
||||||
<form method="post" action="/">
|
<form method="post" action="/">
|
||||||
|
|
|
@ -129,7 +129,7 @@ def parse_query(query):
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def index():
|
def index():
|
||||||
global categories
|
paging = False
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
request_data = request.form
|
request_data = request.form
|
||||||
|
@ -138,6 +138,12 @@ def index():
|
||||||
if not request_data.get('q'):
|
if not request_data.get('q'):
|
||||||
return render('index.html')
|
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 = []
|
selected_categories = []
|
||||||
|
|
||||||
query, selected_engines = parse_query(request_data['q'].encode('utf-8'))
|
query, selected_engines = parse_query(request_data['q'].encode('utf-8'))
|
||||||
|
@ -166,10 +172,12 @@ def index():
|
||||||
'name': x.name}
|
'name': x.name}
|
||||||
for x in categories[categ])
|
for x in categories[categ])
|
||||||
|
|
||||||
results, suggestions = search(query, request, selected_engines)
|
results, suggestions = search(query, request, selected_engines, pageno)
|
||||||
|
|
||||||
featured_results = []
|
featured_results = []
|
||||||
for result in results:
|
for result in results:
|
||||||
|
if not paging and engines[result['engine']].paging:
|
||||||
|
paging = True
|
||||||
if request_data.get('format', 'html') == 'html':
|
if request_data.get('format', 'html') == 'html':
|
||||||
if 'content' in result:
|
if 'content' in result:
|
||||||
result['content'] = highlight_content(result['content'], query)
|
result['content'] = highlight_content(result['content'], query)
|
||||||
|
@ -219,7 +227,8 @@ def index():
|
||||||
results=results,
|
results=results,
|
||||||
q=request_data['q'],
|
q=request_data['q'],
|
||||||
selected_categories=selected_categories,
|
selected_categories=selected_categories,
|
||||||
number_of_results=len(results) + len(featured_results),
|
paging=paging,
|
||||||
|
pageno=pageno,
|
||||||
featured_results=featured_results,
|
featured_results=featured_results,
|
||||||
suggestions=suggestions
|
suggestions=suggestions
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue