mirror of https://github.com/searx/searx
[enh] display number of results
This commit is contained in:
parent
36c8977390
commit
2f7752b410
|
@ -54,6 +54,12 @@ def response(resp):
|
|||
|
||||
dom = html.fromstring(resp.text)
|
||||
|
||||
try:
|
||||
results.append({'number_of_results': int(dom.xpath('//span[@class="sb_count"]/text()')[0]
|
||||
.split()[0].replace(',', ''))})
|
||||
except:
|
||||
pass
|
||||
|
||||
# parse results
|
||||
for result in dom.xpath('//div[@class="sa_cc"]'):
|
||||
link = result.xpath('.//h3/a')[0]
|
||||
|
@ -66,10 +72,6 @@ def response(resp):
|
|||
'title': title,
|
||||
'content': content})
|
||||
|
||||
# return results if something is found
|
||||
if results:
|
||||
return results
|
||||
|
||||
# parse results again if nothing is found yet
|
||||
for result in dom.xpath('//li[@class="b_algo"]'):
|
||||
link = result.xpath('.//h2/a')[0]
|
||||
|
|
|
@ -77,6 +77,13 @@ def response(resp):
|
|||
|
||||
dom = html.fromstring(resp.text)
|
||||
|
||||
try:
|
||||
results_num = int(dom.xpath('//div[@class="compPagination"]/span[last()]/text()')[0]
|
||||
.split()[0].replace(',', ''))
|
||||
results.append({'number_of_results': results_num})
|
||||
except:
|
||||
pass
|
||||
|
||||
# parse results
|
||||
for result in dom.xpath(results_xpath):
|
||||
try:
|
||||
|
|
|
@ -99,6 +99,7 @@ class ResultContainer(object):
|
|||
self._infobox_ids = {}
|
||||
self.suggestions = set()
|
||||
self.answers = set()
|
||||
self.number_of_results = 0
|
||||
|
||||
def extend(self, engine_name, results):
|
||||
for result in list(results):
|
||||
|
@ -111,6 +112,9 @@ class ResultContainer(object):
|
|||
elif 'infobox' in result:
|
||||
self._merge_infobox(result)
|
||||
results.remove(result)
|
||||
elif 'number_of_results' in result:
|
||||
self.number_of_results = max(self.number_of_results, result['number_of_results'])
|
||||
results.remove(result)
|
||||
|
||||
with RLock():
|
||||
engines[engine_name].stats['search_count'] += 1
|
||||
|
|
|
@ -78,6 +78,16 @@
|
|||
</div><!-- /#main_results -->
|
||||
|
||||
<div class="col-sm-4" id="sidebar_results">
|
||||
{% if number_of_results %}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">{{ _('Number of results') }}</h4>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{{ number_of_results }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if infoboxes %}
|
||||
{% for infobox in infoboxes %}
|
||||
{% include 'oscar/infobox.html' %}
|
||||
|
|
|
@ -48,7 +48,7 @@ from flask import (
|
|||
Flask, request, render_template, url_for, Response, make_response,
|
||||
redirect, send_from_directory
|
||||
)
|
||||
from flask.ext.babel import Babel, gettext, format_date
|
||||
from flask.ext.babel import Babel, gettext, format_date, format_decimal
|
||||
from flask.json import jsonify
|
||||
from searx import settings, searx_dir
|
||||
from searx.engines import (
|
||||
|
@ -420,6 +420,7 @@ def index():
|
|||
|
||||
if search.request_data.get('format') == 'json':
|
||||
return Response(json.dumps({'query': search.query,
|
||||
'number_of_results': search.result_container.number_of_results,
|
||||
'results': search.result_container.get_ordered_results()}),
|
||||
mimetype='application/json')
|
||||
elif search.request_data.get('format') == 'csv':
|
||||
|
@ -439,7 +440,7 @@ def index():
|
|||
'opensearch_response_rss.xml',
|
||||
results=search.result_container.get_ordered_results(),
|
||||
q=search.request_data['q'],
|
||||
number_of_results=search.result_container.results_length(),
|
||||
number_of_results=search.result_container.number_of_results,
|
||||
base_url=get_base_url()
|
||||
)
|
||||
return Response(response_rss, mimetype='text/xml')
|
||||
|
@ -450,6 +451,7 @@ def index():
|
|||
q=search.request_data['q'],
|
||||
selected_categories=search.categories,
|
||||
paging=search.paging,
|
||||
number_of_results=format_decimal(search.result_container.number_of_results),
|
||||
pageno=search.pageno,
|
||||
base_url=get_base_url(),
|
||||
suggestions=search.result_container.suggestions,
|
||||
|
|
Loading…
Reference in New Issue