logo

searx

My custom branche(s) on searx, a meta-search engine
commit: 2f7752b410c449aac463c248c0b7e41f69b6b07b
parent: 36c8977390b50259de56cc9678499340c78ee25b
Author: Adam Tauber <asciimoo@gmail.com>
Date:   Tue, 28 Jun 2016 00:06:50 +0200

[enh] display number of results

Diffstat:

Msearx/engines/bing.py10++++++----
Msearx/engines/yahoo.py7+++++++
Msearx/results.py4++++
Msearx/templates/oscar/results.html10++++++++++
Msearx/webapp.py6++++--
5 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/searx/engines/bing.py b/searx/engines/bing.py @@ -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] diff --git a/searx/engines/yahoo.py b/searx/engines/yahoo.py @@ -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: diff --git a/searx/results.py b/searx/results.py @@ -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 diff --git a/searx/templates/oscar/results.html b/searx/templates/oscar/results.html @@ -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' %} diff --git a/searx/webapp.py b/searx/webapp.py @@ -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,