From 9bc24080bf4c24a182cf2b5616095c2f6bea5821 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Fri, 13 Mar 2020 00:43:05 +0100 Subject: [PATCH 1/4] [fix] add answers, suggestions, corrections to rss output fixes #1888 --- .../__common__/opensearch_response_rss.xml | 24 +++++++++++++++++++ searx/webapp.py | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/searx/templates/__common__/opensearch_response_rss.xml b/searx/templates/__common__/opensearch_response_rss.xml index 32c42e7c..3781dd87 100644 --- a/searx/templates/__common__/opensearch_response_rss.xml +++ b/searx/templates/__common__/opensearch_response_rss.xml @@ -25,5 +25,29 @@ {% if r.pubdate %}{{ r.pubdate }}{% endif %} {% endfor %} + {% if answers %} + {% for a in answers %} + + {{ a }} + answer + + {% endfor %} + {% endif %} + {% if corrections %} + {% for a in corrections %} + + {{ a }} + correction + + {% endfor %} + {% endif %} + {% if suggestions %} + {% for a in suggestions %} + + {{ a }} + suggestion + + {% endfor %} + {% endif %} diff --git a/searx/webapp.py b/searx/webapp.py index b661e39d..da2bf34a 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -637,9 +637,13 @@ def index(): response.headers.add('Content-Disposition', cont_disp) return response elif output_format == 'rss': + print(results) response_rss = render( 'opensearch_response_rss.xml', results=results, + answers=result_container.answers, + corrections=result_container.corrections, + suggestions=result_container.suggestions, q=request.form['q'], number_of_results=number_of_results, base_url=get_base_url(), From 018b6818419a1c3044b7d7244b55a62779063071 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Fri, 13 Mar 2020 00:50:19 +0100 Subject: [PATCH 2/4] [fix] add answers, suggestions, corrections to csv output fixes #1888 --- searx/webapp.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/searx/webapp.py b/searx/webapp.py index da2bf34a..49129d14 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -626,10 +626,20 @@ def index(): mimetype='application/json') elif output_format == 'csv': csv = UnicodeWriter(StringIO()) - keys = ('title', 'url', 'content', 'host', 'engine', 'score') + keys = ('title', 'url', 'content', 'host', 'engine', 'score', 'type') csv.writerow(keys) for row in results: row['host'] = row['parsed_url'].netloc + row['type'] = 'result' + csv.writerow([row.get(key, '') for key in keys]) + for a in result_container.answers: + row = {'title': a, 'type': 'answer'} + csv.writerow([row.get(key, '') for key in keys]) + for a in result_container.suggestions: + row = {'title': a, 'type': 'suggestion'} + csv.writerow([row.get(key, '') for key in keys]) + for a in result_container.corrections: + row = {'title': a, 'type': 'correction'} csv.writerow([row.get(key, '') for key in keys]) csv.stream.seek(0) response = Response(csv.stream.read(), mimetype='application/csv') From 58a630308a95f886db9de19d562e11890ac35e07 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Fri, 13 Mar 2020 00:57:01 +0100 Subject: [PATCH 3/4] [fix] convert query to string to produce valid filename for csv output --- searx/webapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searx/webapp.py b/searx/webapp.py index 49129d14..0c5ed457 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -643,7 +643,7 @@ def index(): csv.writerow([row.get(key, '') for key in keys]) csv.stream.seek(0) response = Response(csv.stream.read(), mimetype='application/csv') - cont_disp = 'attachment;Filename=searx_-_{0}.csv'.format(search_query.query) + cont_disp = 'attachment;Filename=searx_-_{0}.csv'.format(search_query.query.decode('utf-8')) response.headers.add('Content-Disposition', cont_disp) return response elif output_format == 'rss': From 8e727ac77f5db59c1b772d9fd7603b519badb35a Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Fri, 13 Mar 2020 01:05:02 +0100 Subject: [PATCH 4/4] [fix] update csv unit test --- tests/unit/test_webapp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py index 72ace485..f31332fa 100644 --- a/tests/unit/test_webapp.py +++ b/tests/unit/test_webapp.py @@ -99,9 +99,9 @@ class ViewsTestCase(SearxTestCase): result = self.app.post('/', data={'q': 'test', 'format': 'csv'}) self.assertEqual( - b'title,url,content,host,engine,score\r\n' - b'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,\r\n' # noqa - b'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,\r\n', # noqa + b'title,url,content,host,engine,score,type\r\n' + b'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,,result\r\n' # noqa + b'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,,result\r\n', # noqa result.data )